JSON Intro

JS Tutorial

JS Version

JS Objects

JS Function

JS Classes

JS Async

JS HTML DOM

JS Browser BOM

JS Web API

JS AJAX

JS JSON

JS vs JQUERY

JS Graphics

JSON Intro

JSON’s full form is JavaScript Object Notation.

JSON is a text format for storing and transporting data.

JSON is “self-describing” and easily understandable.

JSON Example

This example is a JSON string:

‘{“name”:”John”, “age”:30, “car”:null}’

It defines an object with 3 properties:

  • name
  • age
  • car

Each property has a value.

If you parse the JSON string with a JavaScript program, the data as an object can be accessed:

let personName = obj.name;

let personAge = obj.age;

Why Use JSON?

The JSON format is similar to the code for creating JavaScript objects. Due to this, a JavaScript program can convert JSON data into JavaScript objects

As the format is text restricted only, JSON data can easily be sent between computers and used by any programming language.

JavaScript consists of a built-in function for converting JSON strings into JavaScript objects:

JSON.parse()

JavaScript also consists of a built-in function for converting an object into a JSON string:

JSON.stringify()

While storing data, the data needs to be in a particular format, and regardless of where it is stored, the text is always one of the legal formats.

JSON makes it possible to store JavaScript objects as text.