JSON stands for JavaScript Object Notation JSON is a text format for storing and transporting data JSON is "self-describing" and easy to understand JSON is a lightweight Data-Interchange Format. JSON Is Programming Language Independent Subset of Javascript Object literal easy to read Minimum bandwidth is needed to interchange data Supports in all browsers JSON SYNTAX { key:value }
JSON RULES Must create data within curly brackets {} { json data} Data must be written with key-value pairs { key : value } Key and value must be separated by colon : {“name” : “ram”} key should be double-quoted, if the value is a string then it must be double-quoted {“name” : “ sita ”} {“age” : 21}
When multiple data are used then it should be separated by a comma {“name” : “ram” , {“age” : 21} When array data are used then it should be represented in square brackets[] {“marks” : [12,61,99]} curly brackets are used to store/hold/represent objects JSON as a document JSON data can be created in an external file with an extension as.json
JSON Datatypes Number: Integer, Floating point number Eg: {"regno":101, "cgpa":9.1} String : Text with double quotes Eg:{"name": "John"} Boolean : true or false Eg: {"sale": true} Array: Square brackets[] Eg: { "employees":["John", "Anna", "Peter"] } Object: curly brackets, can have objects within objects. Eg: { "employee":{"name": "John", "age":30} } Null : null Eg: {“middle name": null}
Example: <script> var user = new Object(); user.name="Ram"; user.age =23; document.write ("His Name is " +user.name + " < br >And his age is " + user.age ) var user={ name:"SAM ", age:24 } document.write ("< br > His Name is " +user.name + " < br >And his age is " + user.age ) </script> JAVASCRIPT JSON