How do I store JSON data on a disk?

Radek picture Radek · Feb 4, 2010 · Viewed 24.3k times · Source

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 google, I read json.org but I did not understand how to store JSON data.

JSON is is a lightweight data-interchange format. So how I store its data? In a file? In a database? Does it matter?

I can use it to pass the data to jsTree (jsTree is a javascript based, cross browser tree component. It is packaged as a jQuery plugin.) It would be with Wordpress. I am trying to understand how I will store the data? In a file? Text file? In Wordpress database? Which one is faster? Better to use?

CURRENT STATUS before any coding,there is no application running

  • I am preparing the source data and so far my source csv file is 235KB in size with about 700lines (line = future nodes/leaves). I use csv file just to collect data then I will upload/update the data source on the web server.
  • The number is going to grow let's say every week by 5-10.
  • The file is on my local computer and will be stored (somehow) on a webhosting server. Please note that I will use the whole application jsTree+JSON within Wordpress
  • I guess I can use this: Now parse Client side json with Wordpress

Answer

Steve g picture Steve g · Feb 4, 2010

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" : "[email protected]"
}

Might be represented in xml as

<person>
   <id>321</id>
   <name>Jim</name>
   <age>27</age>
   <email>[email protected]</email>
</person>

Or might be stored in the a table that looks like

_______________________________________
| id | name | age | email              |
========================================
|321 | Jim  | 27  |[email protected]     |
----------------------------------------

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.