views:

131

answers:

5
+2  Q: 

understanding json

JSON stands for JavaScript Object Notation. But how come languages like php, java, c etc can also communication each other with json.

What I want to know is that, am i correct to say that json is not limited to js only, but served as a protocol for applications to communicate with each other over the network, which is the same purpose as XML?

A: 

yes, JSON is also wildly used as a data exchange protocol much like XML. Typically a program (not written in JavaScript) needs a JSON library to parse and create JSON objects (although you can probably create them even without one).

Omry
A: 

Your right - it's a light weight data interchange format -- more details at: http://www.json.org

Markus Maria Miedaner
A: 

You are completely correct. JSON definition of how data should be formatted. It is more light weight than XML and therefore well suited to things like AJAX where you want to send data back and forth to the server quickly.

grahamrb
+4  A: 

JSON cannot handle complex data hierarchies like XML can (attributes, namespaces, etc.), but on the other hand you don't get the same overhead with JSON as you get with XML (if you don't need the complex data structures).

Since JSON is plain text with a special notation for JS to interpret, it's an easy protocol to adopt in other languages.

Björn
+1  A: 

It is easy for a JS script to parse JSON, since it can be done using 'eval' in which the JS enginge can use its full power.

On the other hand, it is more complicated to generate JSON from within JS. Usually one uses the JSON package from www.json.org in which an object can easily be serialised using JSON.stringify, but it is implemented in JS so its not running with optimal performance.

So serialising JSON is about the same complexity using JS as when using Java, PHP or any other server side language.

Therefore, in my opinion, JSON is best suited when there is asymmetry between produce/consumer e.g. a web server that generates a lot of data that is consumed by the web application. Not the other way around.

But! When one choses JSON as data format it should be used in both directions, not XML<>JSON. Except for when simple get requests are used to retrieve JSON data.

Ernelli