HTML and CSS Reference
In-Depth Information
JavaScript Object Notation
The previous section demonstrated how simple JavaScript objects are. At heart, JavaScript
objects are simple associative arrays. Each property in the object can have a value that is a
simple type (such as a number or a string), a function, an array, or another type of object.
When writing web-based applications it is often necessary to send data from the client to
the server, or the server to the client. In order to transfer data across a network it must be
encoded in a data format agreed by both the sender and the receiver.
There are many data formats that can be used to send and receive data; of these XML is
probably the most common. An example XML document for representing people might look
as follows:
<person>
<firstName>John</firstName>
<lastName>Smith</lastName>
<age>32</age>
<address>
<city>Los Angeles</city>
<postCode>90245</postCode>
</address>
</person>
XML is a widely used data format, particularly in enterprise applications. It has many be-
nefits, including a wide array of libraries that support it and widespread acceptance in IT
departments. XML is a particularly verbose data format however, in the example above far
more than 75% of the text is made up of tags rather than content.
Before gaining an understanding of JSON, first consider what a JavaScript object may look
like that contained this same data:
> person = {};
> person.firstName = 'John';
> person.lastName = 'Smith';
> person.age = 32;
Search WWH ::




Custom Search