JSON

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
let 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.

let emp = {
  name: "Surya",
  age: 25,
  Role: "Frontend Dev"
};
let 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 )
const 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 )
const 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

  1. JSON is short for JavaScript Object Notation.
  2.  JSON is used to read data from a web server, and display the data in a web page.
  3. In JSON, all keys in an object must be enclosed with double-quotes.