JSON: Difference between revisions

[pending revision][pending revision]
Content deleted Content added
Typo correction
No edit summary
Line 1:
'''JSON''', which stands for "'''J'''ava'''s'''cript '''o'''bject '''n'''otation", is a lightweight data interchange format. '''JSON''' has the advantage, over [[XML]], as a data interchange format in that it can be trivially parsed, by Javascript, with Javascript's built in [[eval]]() procedure. (This is important because of [[Javascript]]'s ubiquitousness amoung [[web browsers]].) '''JSON''' is Javascript's [[object literal]] format.
'''JSON''', which stands for "[[JavaScript]] object notation", is a lightweight data interchange format.
 
== Using JSON and JavaScript ==
'''JSON''' is useful as a data-interchange format because it can be trivially parsed, by Javascript built in [[eval]]() procedure. For example:
Unlike many [[object-oriented programming language]]s, JavaScript objects do not necessarily have to be created by a [[constructor]]. JavaScript objects can be created by an [[object literal]] format. For example:
 
my_object =
{ "name" : "Joe Blow"
, "address" : "123 Somewhere Street"
, "city" : "Surrey"
, "province" : "BC"
, "country" : "Canada"
};
 
This produces a JavaScript object named "my_object" with ''fields'': "name", "address", "city", "province", and "country". One could use this object as follows:
 
document.write("My name is "+my_object.name+".\n");
document.write("And I live on "+my_object.address+" in "+my_object.city+".\n");
 
Which would print out:
 
My name is Joe Blow.
And I live on 123 Somewhere Street in Surrey.
 
'''JSON''' is a JavaScript object literal.
 
eval("the_object = " + json_data + ";");
 
== JSON Pronunciation ==