PARSING AND SERIALIZATION
JSON rose to popularity not necessarily because it used familiar syntax. Rather, it became popular because the data could be parsed into a usable object in JavaScript. This stood in stark contrast to XML that was parsed into a DOM document, making extraction of data into a bit of a chore for JavaScript developers. For example, the JSON code in the previous section contains a list of books, and you can easily get the title of the third book via:
books[2].title
This assumes that the data structure was stored in a variable named books
. Compare this to a typical walk through of a DOM structure:
doc.getElementsByTagName("book")[2].getAttribute("title");
With all of the extra method calls, it's no wonder that JSON became incredibly popular with JavaScript developers. After that, JSON went on to become the de facto serialization standard for web services.
The JSON Object
Early JSON parsers did little more than use JavaScript's eval...