Java Reference
In-Depth Information
JSON
JavaScript Object Notation, or JSON , was invented by Douglas Crockford in 2001. It is
a popular lightweight data-storage format that is used for data serialization and configura-
tion. It is often used to exchange information between web services and is employed by sites
such as Twitter, Facebook, and Trello to share information. It manages to hit the sweet spot
between being both human- and machine-readable.
JSON is a string representation of the object literal notation that we have just seen. There
are a few differences, though, such as property names being quoted and not using functions
to create methods.
Here is an example of a JSON object representing the Caped Crusader:
var batman = '{"name": "Batman","real name": "Bruce
Wayne","height":
74,"weight": 210,"hero": true,"villain": false,"allies":
["Robin",
"Batgirl","Superman"]}'
JSON is becoming increasingly popular as a data storage format and many programming
languages now have libraries dedicated to parsing and generating it. Since ECMAScript 5,
there has been a global JSON object that can be used to do the same in JavaScript.
The parse method takes a JSON string and returns a JavaScript object:
JSON.parse(batman);
<< {"allies": ["Robin", "Batgirl", "Superman"], "height":
74,
"hero": true, "name": "Batman", "real name": "Bruce
Wayne",
"villain": false, "weight": 210}
The stringify method does the opposite, taking a JavaScript object and returning a
string of JSON data, as can be seen in the example:
Search WWH ::




Custom Search