What is JSON?

JSON (JavaScript Object Notation) Is a format to exchange and keep information that’s readable to humans. The document contains only text and uses the expansion .json.

In this report, you will learn about what JSON is used for and how it can enhance your site’s performance.

What’s JSON Used For?

JSON is a format which stores structured data and is mainly utilized to transfer information between a server and a client.

The file is essentially a simpler and more lightweight alternative to XML (Extensive Markup Language) that has similar purposes.

Developers use JSON to operate with AJAX (Asynchronous JavaScript and XML). These formats work well together to attain asynchronous loading of saved information, meaning that a site can upgrade its data without refreshing the page.

This procedure is simpler to do with JSON than XML/RSS. And now, as many sites are embracing AJAX, the”.json” document has become remarkably popular.

Furthermore, it enables users to request information from another domain using a method called JSONP by applying
<script> tags. Otherwise, you can not actually transfer data cross-domains due to the same-origin policy.

JSON Syntax

So as to properly create a “. Json” file, you need to follow the perfect syntax.

There are two core components of a JSON object: Keys and Values.

  • Keys must be strings. They have a sequence of characters which are surrounded by quote marks.
  • Values are a valid JSON data type. It may be in the shape of an array, object, string, boolean, number, or null.

A JSON object starts and ends with curly braces undefined. It may have two or more key/value pairs inside, using a comma to separate them. Meanwhile, each key is followed by a colon to differentiate it in the value.

Here’s an example:

{"city":"New York", "country":"United States "}

We’ve got two key/value pairs here: town and country will be the keys; New York and United States are the values.

Kinds of Values

Values Have a valid JSON data type, for example:

Array

An array is an ordered set of values. It’s surrounded by square brackets [] and every value inside is separated by a comma.

An array value can comprise JSON objects, meaning that it uses the identical key/value pair idea. For example:

 
"students":[
{"firstName":"Tom", "lastName":"Jackson"},
{"firstName":"Linda", "lastName":"Garner"},
{"firstName":"Adam", "lastName":"Cooper"}
]

Information between the square brackets is the array, which has three objects inside.

Object

An Object comprises a key and value. There’s a colon after each key and a comma after each value, which also differentiates between every object. Both of these are inside quote marks.

Object, as a value, must follow the same principle as an object. Like so:

“employees”: {“firstName”:”Tom”, “lastName”:”Jackson”}

Here, workers is your key while everything in the curly braces is the thing.

Strings

A series is a set sequence of zero or more Unicode characters. It’s enclosed by two double quote marks.

This example indicates that Tom suggests a series as it has a set of characters in a double quote.

"firstName":"Tom"

Number

Amount in JSON should be an integer or a floating point, for example

{“age”:”30”}

Boolean

You can use authentic or false for a value, as follows:

{“married”:”false”)

Null

It is to show that there’s not any information.

{“bloodType”:”null”}

Leave a Reply

Your email address will not be published. Required fields are marked *