Database Reference
In-Depth Information
WHAT'S JSON?
JSON, which stands for JavaScript Object Notation, is a data exchange format that serves as an altern-
ative to XML. A basic JSON document for a contact in an address book might look like this:
{
"contact": {
"fname": "Alison",
"lname": "Brown",
"address": {"street": "301 Park Ave", "city": "New York", "state": "NY",
"zip": "10022"},
"phone": [
{ "type": "mobile", "number": "480-555-5555" },
{ "type": "home", "number": "212-444-4444" }
]
}
}
That JSON data would likely be expressed in XML like this:
<contact>
<fname>Alison</fname><lname>Brown</lname>
<address>
<street>301 Park Ave</street><city>New York</city>
<state>NY</state><zip>10022</zip>
</address>
<phone type="mobile">480-555-5555</phone>
<phone type="home">212-444-4444</phone>
</contact>
JSON supports just a few data types, as opposed to the many offered by XML. These are number,
Unicode string, boolean, array, object, and null.
In the preceding JSON document, you can see we have a contact object with a few attributes. The first
and last name are defined as strings. The address attribute has an object value, as the address defines its
own set of attributes. Finally the phone attribute has an array value, which is denoted by the surround-
ing square brackets and the fact that the type attribute is repeated. JSON documents have an associated
Internet media type of application/json .
JSON has been around since 1999, but has grown dramatically in popularity in recent years as deve-
lopers have become tired of what is perceived as bloated XML documents and difficult tooling and APIs.
The simple facts that a typical JSON document contains around 30% fewer characters than the corres-
ponding XML document and that Google started offering JSON as a format for its GData protocol in
2006 probably have had a lot to do with the surge in popularity.
JSON documents are leaner and lighter than XML documents capturing the same data, and although
XML enjoys widespread tooling support on a variety of platforms, JSON documents are very simple and
Search WWH ::




Custom Search