JSON is a minimal, readable format for structuring data.
Features of JSON:
- It is light-weight
- It is language independent
- Easy to read and write
- Text based, human readable data exchange format
Much Like XML Because:
- Both JSON and XML is "self describing" (human readable)
- Both JSON and XML is hierarchical (values within values)
- Both JSON and XML can be parsed and used by lots of programming languages
- Both JSON and XML can be fetched with an XMLHttpRequest
Much Unlike XML Because:
- JSON doesn't use end tag
- JSON is shorter
- JSON is quicker to read and write
- JSON can use arrays
The biggest difference is:
For AJAX applications, JSON is faster and easier than XML.
- Fetch an XML document
- Use the XML DOM to loop through the document
- Extract values and store in variables
- Fetch a JSON string
- JSON.Parse the JSON string
JSON Syntax Rules
- Data is in name/value pairs
- Data is separated by commas
- Curly braces hold objects
- Square brackets hold arrays
- The file type for JSON files is ".json"
- The MIME type for JSON text is "application/json"