JSON is smaller than XML, and faster and easier to parse.
- JSON stands for JavaScript Object Notation
- JSON is lightweight text-data interchange format
- JSON is language independent
- JSON is "self-describing" and easy to understand
JSON Example
{
"student": [
{ "firstName":"Joe" , "lastName":"Doe" },
{ "firstName":"Jhon" , "lastName":"Smith" },
{ "firstName":"Jhony" , "lastName":"Jones" }
]
}
The student object is an array of 3 student records (objects).
JSON uses JavaScript syntax for describing data objects, but JSON is still language and platform independent. JSON parsers and JSON libraries exists for many different programming languages. |
JSON - Evaluates to JavaScript Objects
The JSON text format is syntactically identical to the code for creating JavaScript objects.
Because of this similarity, instead of using a parser, a JavaScript program can use the built-in eval() function and execute JSON data to produce native JavaScript objects.
Much Like XML
JSON is plain text
JSON is "self-describing" (human readable)
JSON is hierarchical (values within values)
JSON can be parsed by JavaScript
JSON data can be transported using AJAX
Much Unlike XML
No end tag
Shorter
Quicker to read and write
Can be parsed using built-in JavaScript eval()
Uses arrays
No reserved words
Why JSON?
For AJAX applications, JSON is faster and easier than XML:
- Using XML
-> Fetch an XML document
-> Use the XML DOM to loop through the document
-> Extract values and store in variables
- Using JSON
-> Fetch a JSON string
-> eval() the JSON string
JSON Syntax Rules
JSON syntax is a subset of the JavaScript.
- Data is in name/value pairs
- Data is separated by commas
- Curly braces hold objects
- Square brackets hold arrays
JSON Files
- The file type for JSON files is ".json"
- The MIME type for JSON text is "application/json"
No comments:
Post a Comment