JSONvsXML
JSONvsXML
Krishna Priya
Learning goals
• What is JSON?
• Why JSON needed?
• JSON syntax rules
• JSON key-value pair
• JSON objects and arrays
JavaScript Object Notation (JSON)
Curly braces hold objects and each name is followed by ':'(colon), the name/value pairs are separated by ,
(comma).
{
"id":"01",
"language": "Java",
"edition": "third",
"author": "Herbert Schildt",
},
{
"id":"07",
"language": "C++",
"edition": "second",
"author": "E.Balagurusamy",
} ] }
JSON data structure
• An object begins with {(left brace) and ends with }(right brace). Each name is followed
by :(colon) and the name/value pairs are separated by ,(comma).
• The string value must be enclosed within double quote " ".
• JSON supports numbers in double precision floating-point format digit, fraction and
exponent
JSON Object
{''student'':{
"firstName" : "json",
"hometown" : "Hyderabad",
"age" : "28"
}}
JSON Array
An ordered list of values. In most languages, this
is realized as an array, vector, list, or sequence.
An array is an ordered collection of values. An
array begins with [(left bracket) and ends with ]
(right bracket). Values are separated by ,
(comma).
JSON Arrays
"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter","lastName":"Jones"}
]
In the example above, the object "employees" is an array containing three objects. Each object is a
record of a person (with a first name and a last name).
var employees = [
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter","lastName": "Jones"}
];
The first entry in the JavaScript object array can be accessed like this:
Example
// returns John Doe
employees[0].firstName + " " + employees[0].lastName;
JSON examples
{
"persons": [
{
"firstName": "Munsub", {
"LastName": "Ali", "firstName": "Anser",
"Age": 26, "LastName": "Ali",
"Address": "Binghamtom, NY USA", "Age": 28,
"PhoneNo": "1234-567-891011", "Address": "Greenville, PA USA",
"id": 1 "PhoneNo": "1234-567-891012",
}, "id": 3
{ }
"firstName": "Noor", ]
"LastName": "ulHaq", }
"Age": 40,
"Address": "Philadelphia, PA USA",
"PhoneNo": "1234-567-891013",
"id": 2
},
References
1. https://restfulapi.net/json-data-types/
THANK YOU