3. JSON - Introduction
JSON is a light-weight alternative to XML for data-interchange
JSON = JavaScript Object Notation
◦ It’s really language independent
◦ most programming languages can easily read it and instantiate objects or some other data structure
Defined in RFC 4627
Started gaining tracking ~2006 and now widely used
http://json.org/ has more information
5/23/2015 3
4. Example
This is a JSON object with five key-value pairs
Objects are wrapped by curly braces
There are no object IDs
Keys are strings
Values are numbers, strings, objects or arrays
Arrays are wrapped by square brackets
{
"firstName": "John",
"lastName" : "Smith", "age" : 25,
"address" :
{
"streetAdr” : "21 2nd Street", "city" : "New York",
"state" : "NY", ”zip" : "10021“
},
"phoneNumber":
[
{"type" : "home", "number": "212 555-1234"},
{"type" : "fax", "number” : "646 555-4567"}
]
}
5/23/2015 4
10. JSON vs. XML (Data Exchange Formats)
Criteria JSON XML
AJAX
The X in AJAX
JavaScript baby Needs more libraries
Namespaces No Yes
Input validation No Yes
Transmission time less more
Verbosity less more
Web services
REST SOAP
REST is more popular in
non-critical applications
SOAP is more reliable is business
applications
5/23/2015 10
11. JSON vs. XML (Case Study)
5/23/2015
Comparison of JSON and XML Data Interchange Formats: A Case Study - Montana State
University – Bozeman
Scenario 1: 1 million objects.
Scenario 2: 5 samples (20000, 40000, 60000, 80000, 100000) objects with statistical analysis.
11
13. Conclusion
JSON is a light weight text format for data exchange.
Simple BNF: objects, arrays, values (strings, numbers, null).
JSON is much faster than XML in AJAX applications.
REST + AJAX are the boosters of JSON.
ADE should include JSON not only XML.
5/23/2015 13