JavaScript Object Notation (JSON):
JSON is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and arrays. It is a common data format with diverse uses in electronic data interchange, including that of web applications with servers.
JSON is short for JavaScript Object Notation, and is a way to store information in an organized, easy-to-access manner.
A common use of JSON is to read data from a web server, and display the data in a web page.
JSON is a data representation format used for:
- Storing data (Client/Server)
- Exchanging data between Client and Server
JSON Supported Types :
- Number
- String
- Boolean
- Array
- Object
- Null
Syntaxlet emp = { "key": "value", "key": "value", "key": "value" };
JS Object vs JSON Object
In JSON, all keys in an object must be enclosed with double-quotes. While in JS, this is not necessary.
JavaScriptlet emp = { name: "Surya", age: 25, Role: "Frontend Dev" };
JSONlet emp = { "name": "Surya", "age": 25, "Role": "Frontend Dev" };
JSON Methods :
We have two methods they are
1. JSON.stringify() : It converts the given value into JSON string
Syntax:
JSON.stringify( value )
Exampleconst person = {name: "Surya", age: 25, city: "Hyderabad"}; const conatiner = JSON.stringify(person); console.log(person);
2. JSON.parse() : It parses a JSON string and returns a JS object.
Syntax:
JSON.parse( string )
Exampleconst bikes = '["R15", "BMW", "pulsar200"]'; const myArr = JSON.parse(bikes); console.log(myArr);
JSON support is included in all major browsers and in the latest ECMAScript (JavaScript) standard:
Web Browsers Support
- Firefox 3.5
- Internet Explorer 8
- Chrome
- Opera 10
- Safari 4
