2. Agenda What is JSON? Why JSON? Pros and Cons JSON Syntax JSON Parser Accessing Data in JSON
3. What is JSON? Stands for JavaScript Object Notation Is lightweight format for exchanging data between the client and server. Easy for humans to read and write. Easy for machines to parse and generate Often used in Ajax applications due to Its simplicity its format which is based on JavaScript object literals
4. Why JSON? JSON is recognized natively by JavaScript Simple format The easiness of reading The easiness of using Lighter than XML
7. JSON Syntax For objects start the object with “{“ and end it with “}” For members (properties), use pairs of string : value and separate them by commas For arrays put the arrays between [] For elements put the values directly separated by commas
8. Example var myFirstJSON ={ "firstName" : "John", "lastName" : "Doe", "age" : 23 };
9. JSON Parser You can convert JSON object into JSON text Object to Text Conversion var myJSONText = myObject.toJSONString();
10. Accessing Data in JSON The most common way to access JSON data is through dot notation. var myObject = { 'color' : 'blue' };document.writeln(myObject.color);