What is JSON?

Ken Fedorov
3 min readSep 5, 2020

--

JSON or JavaScript Object Notation is a format for storing and exchanging human-readable information. Although JSON began its distribution with JavaScript, it is supported in most languages, either natively or using special libraries. JSON is usually used for exchanging information between web clients and a web server.

JSON Statham

In this article, you will learn what JSON is used for and how it can improve the performance of your site.

What is JSON used for?

JSON is a format that stores structured information and is mainly used for data transfer between the server and the client.

A JSON file is a simpler and easier alternative to an extension with similar XML functions

JSON syntax

To create JSON correctly, you must follow the correct syntax.

There are two main elements of a JSON object: keys and values.

Keys must be strings. They contain a sequence of characters that are enclosed in quotes. The best way to create keys is camelCase.
Values are a valid JSON data type. They can be in the form of an array, an object, a string, a Boolean value, a number, or a null value.

The JSON object starts and ends with brackets {}. Inside may be two or more pairs of keys/values with a comma for splitting them. Meanwhile, each key is followed by a colon to distinguish it from the value.

For example:
{“brand”:”BMW”, “model”:”320i“}

We have two key/value pairs: the keys are the brand and model; the BMW and 320i are the values.

Value type

The values contain a valid JSON data type, for example:

Array

An array is an ordered collection of values. It is enclosed in square brackets [], and each value inside is separated by a comma.

The array value can contain JSON objects, which means it uses the same concept of key/value pairs. For example:

"articles":[      
{"creatorId":185, "creatorName":"Michael"},
{"creatorId":186, "creatorName":"John"},
{"creatorId":187, "creatorName":"Rob"},
]

The information in square brackets is an array containing three objects.

Object

The object contains a key and a value. Each key is followed by a colon, and each value is followed by a comma, which also distinguishes each object. Both of them are inside quotation marks.

The object as a value must follow the same rule as the object. For example:

airplane”: {"brand":"Cessna", "model":172}

Here, airplane are the key, and everything inside curly brackets is an object.

String

String — a specified sequence of zero or more Unicode characters enclosed in two double quotes.

This example shows that the volume represents a string because It is a set of characters inside double quotes.

"brand":"Cessna"

Number

The number in JSON must be an integer or a floating point, for example:

"model":172

Boolean type

You can use true or false as the value, as shown below:

"active":true

null

Lack of information.

"deletedAt":null

Stored JSON Data

You have two ways to store data: a JSON object and an array. The first one looks like this:

airplane”: {
"brand":"Cessna",
"model":172
}

Curly brackets indicate that this is a JSON object. It includes two comma-separated key/value pairs.

In each pair, you have keys (brand and model) followed by colons to distinguish them from values (Cessna, 172).

The values in this example are strings. This is why they are also enclosed in quotation marks, similar to keys.

Using Arrays

Another way to store data is an array. Take a look at this example:

airplane”: {
"brand":"Cessna",
"model":172,
"pilots": ["Jack", "John", "Michael"]
}

What makes this method different from the previous one? So this is the fourth key/value pair. Pilots are a key, and there are several values in square brackets (Jack, John, Michael) that represent an array.

Conclusion

As you can see, JSON is a useful tool for data exchange. It has many advantages:

It can load information asynchronously to make your site more responsive and handle the data flow better.
It has an intuitive structure
JSON is simpler and weighs less than XML.

(.❛ ᴗ ❛.)

--

--