JSON - Introduction


HTML
JSON

JSON is short for JavaScript Object Notation.

JSON is a way to store and move data. It uses a text format.

JSON is like a note that describes itself, making it easy to grasp.

JSON Example

Here is a JSON string example:

'{"name":"John", "age":30, "car":null}'

It creates something with three characteristics.

  • name
  • age
  • car

Every characteristic has its own value.

When you read the JSON string using JavaScript, you can use it like an object in your program.

let personName = obj.name;
let personAge = obj.age;

What is JSON?

  • JSON stands for JavaScript Object Notation.
  • JSON is a simple way to share information.
  • JSON is just text written in a specific way called JavaScript object notation.
  • JSON is a tool for transferring information between computers.
  • JSON can be used with any programming language *.

*
JSON syntax comes from JavaScript object notation, but JSON is only in text format.

In lots of programming languages, there are codes for both reading and creating JSON files.

The JSON format was created by Douglas Crockford.


Why Use JSON?

The JSON format looks a lot like the code used to make JavaScript objects. That's why a JavaScript program can change JSON data into JavaScript objects without much trouble.

JSON data, being text-based, can move effortlessly between computers and work with any programming language.

JavaScript comes with a handy function that turns JSON strings into JavaScript objects.

JSON.parse()

JavaScript includes a built-in function to change an object into a JSON string.

JSON.stringify()

You can get plain text from a server and treat it like a JavaScript object.

You can transmit a JavaScript object to a server in plain text.

You can handle information as JavaScript objects without needing complex conversions or translations.


Storing Data

When you save information, it needs to be in a specific format. Whether you decide to store it in different places, using text is always an acceptable format.

JSON allows storing JavaScript objects in text format.