Skip to Main Content
Programming Atlas
book

Programming Atlas

by Christian Wenz
September 2006
Intermediate to advanced content levelIntermediate to advanced
408 pages
10h 38m
English
O'Reilly Media, Inc.
Content preview from Programming Atlas

JSON

A third major technology often used for Ajax applications is JavaScript Object Notation (JSON, http://www.json.org). With JSON, JavaScript objects or data can be persisted (serialized) in a short and easily understandable way, without requiring a lot of JavaScript code to either write or read the data. JSON makes use of an often-overlooked feature of JavaScript, or to be exact of the ECMAScript language specification, also known as ECMA-262.

JSON is used internally by current versions of Atlas and generally can be used to exchange complex data with a server. This allows JavaScript to understand it, also the sometimes cumbersome XML parsing with JavaScript can be avoided. The following code uses JSON to define a book object.

{"book": {
  "title": "Programming Atlas",
  "author": "Christian Wenz",
  "chapters": {
    "chapter": [
      {"number": "1", "title": "Introduction"},
      {"number": "2", "title": "JavaScript"},
      {"number": "3", "title": "Ajax"}
    ]
  }
}}

This is the same data that you saw defined using XML in Chapter 2. The object with the book property contains title, author, and chapters properties. The chapters property contains several chapter subelements, each with a number and a title property. This can be best visualized when looking at it as XML data. You will remember it as the exact same XML that was used in the previous section, "The XMLDocument Object,” as shown in this code:

<book title="Programming Atlas" author="Christian Wenz"> <chapters> <chapter number="1" title="Introduction" ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Go Systems Programming

Go Systems Programming

Mihalis Tsoukalos

Publisher Resources

ISBN: 0596526725Supplemental ContentCatalog PageErrata