Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 20: JSON > Parsing and Serialization

PARSING AND SERIALIZATION

JSON’s rise to popularity was not necessarily because it used familiar syntax. More so, it was 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 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 standard for web services.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial