Java Reference
In-Depth Information
The final difference is the lack of a trailing semicolon after the closing curly brace. This isn't a
JavaScript statement, and thus, the semicolon is not needed.
The size of this JSON data structure is 69 bytes. That's 68 percent of the 101 bytes of the equivalent
XML.
Like JavaScript objects, JSON objects can be simple or complex. The data structure representing
John Doe is rather simple, but you can easily add complexity by incorporating his address:
{
"firstName": "John",
"lastName": "Doe",
"age": 30,
"address": {
"numberAndStreet": "123 Someplace",
"city": "Somewhere",
"state": "Elsewhere"
}
}
This adds an address property to the main object, and its value is another object that contains
John's mailing address.
arrays
Like objects, arrays in JSON are similar to JavaScript's array literal notation. The following line of
code is an array literal in JavaScript:
var values = ["John", 30, false, null];
The same array looks like this in JSON:
["John", 30, false, null]
Again, notice the JSON array does not have the values variable, nor does it have the trailing
semicolon. And like objects, arrays are not limited to just simple values; they can contain complex
objects, too:
[
{
"firstName": "John",
"lastName": "Doe",
"age": 30,
"address": {
"numberAndStreet": "123 Someplace",
"city": "Somewhere",
"state": "Elsewhere"
}
},
{
"firstName": "Jane",
"lastName": "Doe",
 
Search WWH ::




Custom Search