views:

487

answers:

4

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
+5  A: 

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.

Steve g
@Steve g: is it good idea to have another database if all is going to 'happen with wordpress'?
Radek
+3  A: 

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.

Evan Carroll
+1  A: 

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.

Alxandr
A: 

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. :-)

Laurence Gonsalves
@Laurence Gonsalves: I thought that 235KB html would be too big. So I might need to use something else.
Radek