Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I store JSON data on a disk?

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
like image 599
Radek Avatar asked Feb 04 '10 19:02

Radek


2 Answers

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.

like image 138
Steve g Avatar answered Nov 02 '22 08:11

Steve g


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.

like image 20
NO WAR WITH RUSSIA Avatar answered Nov 02 '22 09:11

NO WAR WITH RUSSIA