JavaScript Tutorial

JSON – Introduction

JSON stands for: JavaScript Object Notation.

JSON is a syntax for storing and exchanging data.

JSON is text, written(in key value pair) with JavaScript object notation.

What is JSON?

  • JSON stands for JavaScript Object Notation
  • JSON is a lightweight data-interchange formatted string written in key value pair
  • JSON is "self-describing" and easy to understand
  • JSON is language independent

Why use JSON?

As the JSON format is lightweight text only, it can simply be sent to and from a server, and used as a data format by any programming language.

JavaScript has a built in or perdefined function to convert a string, written in JSON format, into native JavaScript objects:

JSON.parse()

The JSON.parse() method is a built-in JavaScript function that parses a JSON string and converts it into a JavaScript object. Once the JSON string is parsed, the user can access and manipulate the data within the JavaScript object using standard JavaScript object notation and methods.

Exchanging Data

While exchanging the data between a browser and server, the data can only be text.

JSON is text, and we can convert any JavaScript object into JSON, and send JSON string to the server easily.

By doing this way user can work with the data as JavaScript objects, without any problem in parsing and translations.

Sending Data

If the user has data stored in a JavaScript object, you can convert the object into JSON, and send it to a server:

Input:-

Output (Before json code execution):-

Output (After json code execution the user will be redirected to demo.php):-

Receiving Data

If you receive data in JSON format, you can convert it into a JavaScript object:

Input:-

Output :-

Go back to Previous Course