How do I store JSON data on a disk?

后端 未结 4 1333
日久生厌
日久生厌 2021-02-08 08:25

I am totally new to JSON and I might need to use it in the future so I did some reading bout it. There\'s lots of questions regarding JSON on SO. I found heaps of articles using

相关标签:
4条回答
  • 2021-02-08 09:04

    Weather you store it in a database or in a file doesn't really matter. The point is that you need to be able to fetch it as a string (using HTTP or some server-side-script).

    For instance if you save it as a file named data.json you could use ajax to fetch it, but if you store it in a database you need to use some kind of server-scripting (you could still use ajax though).

    If you have any experience with xml just think of json as the same thing, it's just a string-representation of data.

    0 讨论(0)
  • 2021-02-08 09:07

    I guess the first thing to understand is that JSON is just one way of representing information. You can store the data however you like. If you have a relational database, you can probably come up with a reasonable way of converting the data back and forth.

    { 
      "id": 321
      "name" : "Jim",
      "age" : 27,
      "email" : "jim@jimsoft.com"
    }
    

    Might be represented in xml as

    <person>
       <id>321</id>
       <name>Jim</name>
       <age>27</age>
       <email>jim@jimsoft.com</email>
    </person>
    

    Or might be stored in the a table that looks like

    _______________________________________
    | id | name | age | email              |
    ========================================
    |321 | Jim  | 27  |jim@jimsoft.com     |
    ----------------------------------------
    

    So if you can store the information however you want. You just need some way to serialize/unserialize the data into whatever form you want.

    All that being said, If you need to store the JSON and storing it as a file won't work, You probably want to look at CouchDB or MongoDB. They are document-oriented databases that actually store JSON documents. They will let you store whatever JSON documents you want. You can build views and and query the data directly without having to convert the data to different forms.

    0 讨论(0)
  • 2021-02-08 09:07

    Somethings like CouchDB are a database that store it internally in a file. Most people don't /store/ JSON at all, they generate it and send it, or parse it and process it.

    JSON is an ideal format for serializing data, but the same caveats apply to it as any other serialization format. Do you store XML in a DB? Usually not. The difference being XML makes sacrifices to include humans use, and JSON makes sacrifices to be easily parseable and fast.

    JSON is not really a replacement for a CSV. Think of a CSV as loosely-formated table specific dumping mechanism. It wouldn't make too much sense to have a JSON export in excel.

    0 讨论(0)
  • 2021-02-08 09:21

    JSON is an interchange format. You can store it in a file or a DB if you want, just like any other format, though whether that's a good idea depends on exactly what you're doing.

    You say "So far my source csv file is 235KB in size with about 700lines (nodes/leaves)". Are you considering switching from CSV to JSON? (You don't really say.) You also say "The number is going to grow let's say every week by 5-10". Neither CSV or JSON are really optimal for large files that will have incremental changes applied, except with CSV you can append data efficiently. If appending is all you're doing you could stick with CSV, but if you need to do other modifications, I'd probably decompose the data into a DB so that updates could be made efficiently.

    Actually, the amount of data you're talking about is pretty small, and with such a small number of updates per week, you probably don't need to worry about efficiency. Do whatever you want. :-)

    0 讨论(0)
提交回复
热议问题