JSON Introduction
Online Example
With our editor, you can edit JavaScript code online and then view the results by clicking a button:
JSON Example
Similarities with XML
- JSON is pure text
- JSON is "self-describing" (human-readable)
- JSON has a hierarchical structure (values within values)
- JSON can be parsed by JavaScript
- JSON data can be transmitted using AJAX
Differences with XML
- No end tags
- Shorter
- Faster read and write speeds
- Can be parsed using JavaScript's built-in eval() method
- Uses arrays
- Does not use reserved words
Why Use JSON?
For AJAX applications, JSON is faster and easier to use than XML:
Using XML
- Read the XML document
- Use XML DOM to loop through the document
- Read values and store them in variables
Using JSON
- Read the JSON string
- Process the JSON string with eval()