JSON and JavaScript

JSON stands for JavaScript Object Notation. Just like how we use XML to transfer the information, JSON also does the same thing.Difference between XML and JSON is that we do not need to use tags in JSON format. Data is stored in JavaScript object format.
Another difference is that we can also store arrays in JSON. Also it is very easy to convert the JSON string in JavaScript Object. Once JSON data is converted into object, we can access the properties using the same syntax as we do in JavaScript.

Extension of the JSON file is “.json” and MIME type is “application/json” which can be set in the Content-Type header of HTTP request.

Simple JSON example

var carJSON = ‘{ “cars” : [‘ +
‘{ “name”:”i30″ , “manufacturer”:”Huyndai” },’ +
‘{ “name”:”A8″ , “lastName”:”Audi” } ]}’;

var jsonObject = JSON.parse(carJSON)

console.log (“first car name -> ” + jsonObject.cars[0].name)

You may also like...