JavaScript Tutorial
JS - Introduction JS - Basic JS - Placement JS - Output JS - Statements JS - Syntax JS - Variables JS - Comments JS - Data Types JS - Operators JS - Operator Precedence JS - Condition JS - Switch JS - Functions JS - Objects JS - Loops For JS - Loops While JS - Break JS - Strings JS - String Methods JS - Numbers JS - Number Methods JS - Arrays JS - Array Methods JS - Array Iteration JS - Events JS - Event Listener JS - Event Propagation JS - Date JS - Math JS - Random JS - Boolean JS - Type Conversion JS - RegExp JS - Exception JS - Scope JS - Debugging JS - Hoisting JS - Strict Mode JS - this Keyword JS - Mistakes JS - Best Practices JS - Performance JS - Form Validation JS - ES6 Features
JS Objects
Object Definitions Object Properties Object Methods Object Constructors Object Prototypes
JS Functions
Function Definitions Function Parameters Function Call Function Apply Function Closures
DOM Introduction DOM Methods DOM Selectors DOM HTML DOM CSS DOM Attributes DOM Navigation
JS Browser BOM
JS - Window JS - Screen JS - Location JS - History JS - Navigator JS - Popup Alert JS - Timing JS - Cookies
AJAX - Introduction AJAX - XMLHttp AJAX - Request AJAX - Response AJAX - PHP
JSON - Introduction JSON - Syntax JSON - Data Types JSON - Parse JSON - Stringify JSON - Objects JSON - Arrays JSON - PHP JSON - JSONP
JS References
JavaScript Reference JavaScript Methods HTML DOM Reference

JSON Introduction

JSON stands for JavaScript Object Notation. It is used for storing and exchanging data between server and client.

JSON is extremely lightweight data-interchange format which is quick and easy to parse and generate.

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

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

We can also convert any JSON received from the server into JavaScript objects.

Sending Data

If you have data stored in a JavaScript object, you can convert the object into JSON, and send it to a server.

The following example converts a JavaScript object into a JSON string, and send it to the server:

Run code

You will learn more about the JSON.stringify() method later in this tutorial.

Receiving Data

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

The following example converts a string written in JSON format, into a JavaScript object:

Run code

You will learn more about the JSON.parse() method later in this tutorial.

Storing Data

JSON makes it possible to store JavaScript objects as text.

The following example shows how to use JSON to store and retrieve information of a user in local storage:

Run code

To learn more about LocalStorage object, visit our HTML5 Web Storage API.

What is JSON?

JSON is a lightweight text-based open standard designed for human-readable data interchange.

  • JSON stands for JavaScript Object Notation
  • JSON format was specified by Douglas Crockford
  • JSON was designed for human-readable data interchange
  • JSON has been extended from the JavaScript scripting language
  • JSON is "self-describing" and easy to understand
  • JSON is language independent
  • The filename extension of JSON is .json
  • JSON Internet Media type is application/json
  • The Uniform Type Identifier is public.json

JSON uses JavaScript syntax, but the JSON format is text only.

Text can be read and used as a data format by any programming language.

Why use JSON?

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

JSON format is used for serializing and transmitting structured data over network connection.

JavaScript has a built in function JSON.parse() to convert a string, written in JSON format, into native JavaScript objects.

So, if you receive data from a server, in JSON format, you can use it like any other JavaScript object.