Knowledge Base Hub

Browse through our helpful how-to guides to get the fastest solutions to your technical issues.

Home  >  Web Hosting FAQ  >  What Is JSON? Everything That You Need To Know About It
Top Scroll

What Is JSON? Everything That You Need To Know About It

 3 min

JavaScript Object Notation (JSON) is an open-standard file format, used to exchange information that is readable to humans. This file contains only text and uses the extension .json.
It is a lightweight format used for storing and transporting data between a server and web application, as an alternative to the XML. In simple words, JSON gives a human-readable collection of data that we are able to access in a logical manner.

Usage of JSON –

Most of the developers use JSON so as to work with AJAX (Asynchronous JavaScript and XML). Both these formats work well together in order to provide you the asynchronous loading of stored data that simply means, the website can update its information without refreshing the page.
This format is often used to serialize and transmit structured data over a network connection.
It also allows users to request data from a different domain with the help of a method called as JSON by using (<script>) ) tags. Without this, you cannot transfer data across-domains.

Structures of JSON –

JSON is built on two structures :
(i) A collection of name/value pairs. In most of the languages, this is known as an object, record, dictionary, struct, hash table, keyed list or an associate array.

(ii) An ordered list of values. In most of the languages, this is known as an array, vector, list, or sequence.

Related:  Why Should You Shift Your Java Applications To MilesWeb PaaS Containers?

JSON syntax rules :

(i) Data is always in key/value pair.
(ii) Data is always separated by commas.
(iii) Curly braces hold objects.
(iv) Square brackets hold arrays.

Example : “gender” : “male”
Here: key (name) = gender and
value = male

Different types of Values are :

(i) Array – Array of values

e.g :

"students":[
{"firstName": "Jack", "lastName": "Timothy"},
{"firstName": "Sam", "lastName": "Green"}
]

Or

{
"firstName" : "Jack",
"lastName" : "Timothy",
"gender" : "male",
"hobby" : ["football", "painting", "swimming']
}

Note: Difference here is that, the key Hobby has several values (football, painting, swimming) mentioned in a square brackets, which represents any array.

(ii) Boolean – True or False

{"sale" : "false"}

(iii) Number – An integer

{"age" : "25"}

(iv) Object – It is an associate array of key/value pairs

{
"id" : "48",
"language" : "Java",
"price" : 500,
}

(v) String – Several plain characters that usually form a word

"firstName" : "Jack"

If you want to store JSON data, there are two way to accomplish it. First is objects and the next one is arrays. In this section, we will discuss more about them below.

Using Objects

Curly brackets begin and end a JSON object. Comma-separated lines contain key/value pairs called properties. Each key and value are separated by a colon.

Strings are required for keys, but numbers, objects, arrays, booleans, and nulls are allowed for values.

There is a difference between JSON objects and objects in the JSON data type. Arrays of key-value pairs serve as a storage method, while associative arrays represent key-value pairs.

Now for your convenience, let’s take the example of three keys, Name, roll number and class with values like Thomas, 24 and 7 A.

{

“Name”:”Thomas”,

“rollnumber”:”24″,

“Class”:”7A”

}

Using Arrays

The use of arrays is another method of storing data. Each line is separated by a comma, with the values enclosed in square brackets. It is possible to have different types of values in JSON arrays.

As opposed to arrays as values, JSON arrays are collections of elements that are typically all the same type.

Let’s have an overview as an example:

{

“Name”:”Thomas”,

” rollnumber “:”24”,

“Class”:”7A”,

“subjects”: [

“english”,

“science”,

“maths”

]

}

What Differs Both?

The fourth key/value pair differentiates this method from the previous one. The key is subjects, and there are several values in the square brackets (english, science, maths).

When paired with JSONP, arrays can be used to overcome cross-domain issues. Furthermore, they support loops, allowing users to run repeated commands to look up data faster.

Conclusion –

From the above examples, you might have understood that JSON is a useful tool that can be used to interchange data in a manner that can easily be understood by humans.

It can load information asynchronously so that, your website becomes more responsive and can handle the data stream more easily. Also, JSON is easy and lightweight than XML.

For our Knowledge Base visitors only
Get 10% OFF on Hosting
Special Offer!
30
MINS
59
SECS
Claim the discount before it’s too late. Use the coupon code:
STORYSAVER
Note: Copy the coupon code and apply it on checkout.