JavaScript Tutorial

Javascript JSON

JSON stands for Javascript Object Notation. JSON is a text-based data format that is used to store and transfer data.

In JSON, the data are in key/value pairs separated by a comma.

It was derived from JavaScript. So, the JSON syntax resembles JavaScript object literal syntax. However, the JSON format can also be accessed and created by other programming languages.

JSON Data

This json type of data consists of key/value pairs similar to JavaScript object properties. The key and values are written in double quotes separated by a colon a like,

"name": "Mike"

JSON Object

JSON objects contain multiple key/value pairs. These objects are written inside curly braces { }.

JSON Array

This type of JSON is enclosed within the array and we can have multiple objects in it. JSON array is written inside square brackets [ ].

Accessing JSON Data

We

Output:-

Converting JSON Text to Javascript Object

The most common use of JSON is to read data from a web server and display it on a web page. To convert JSON text to a JavaScript object, you can follow these steps:

  1. Create a JavaScript string that contains JSON syntax. JSON syntax uses key-value pairs and data types similar to JavaScript objects.
  2. Use the built-in function JSON.parse() to parse the JSON string and convert it into a JavaScript object. JSON.parse() takes the JSON string as input and returns the corresponding JavaScript object.

Input:-

Output:-

Go back to Previous Course