/

August 5, 2024

All About JSON In Shopify

What is JSON:

JavaScript Object Notion, commonly known as JSON, is one of the most popular data transition formats

JSON is widely accepted in the software to exchange the data between client-server

JSON is not language but its data and its easy to understand human readable and text based format.

 

Characteristics of JSON

JSON is easy to read and write.

It is a lightweight text-based interchange format.

JSON is language independent

 

Properties of JSON

It is a text-based, lightweight data interchange format.

It has been extended from the JavaScript language.

Its file extension is .json.

Being a text-based format, it is easy to read and write by both the user/programmer and the machines.

It is platform and language independent and inbuilt supported by almost all of the front line

languages/frameworks like and support for the JSON data format is available in all the

popular languages, some of which are C#, PHP, Java, C++, Python, Ruby and many more.

It is used while writing JavaScript based applications that include browser extensions and websites

It can be used with modern programming languages.

 

Usage of JSON

JSON is mostly used to transfer the data from one system to another. It can transfer data between two computers, database, programs etc.

It is mainly used for transmitting serialized data over the network connection.

It can be used with all the major programming languages.

Useful in data transition from the web application to the server.

Most of the web services use JSON based format for data transfer.

 

Syntax of JSON

Let’s take a look at the basic syntax which is used in forming a JSON.

JSON can be basically classified by being built on two structural entities. They are a collection of name-value pairs and the ordered list of values.

JSON is a universal data structure as most of the programming language available today support them

The name value pair collection is realized as an object, strut, record, dictionary etc.

The ordered value list is realized as an array, list etc.

 

Let’s assume we have a student object with the following basic properties and their attributes:

sid: 01

Name: codecrew

Branch : IT

Contact no = 1234567890

 

So, if we want to transfer this data using a JSON file, then the serialization of this data will create a JSON.

{

“sid”        : “01”,

“Firstname”      : “codecrew”,

“lastname”     : “infotech”,

“Contact no” : “1234567890”

}

 

 

What is JSON object?

A JSON Object is surrounded by curly braces and contains key-value pairs.

{ “key21”: “value1”, “key2”: “value2”, “key3”: “value3”  … }

 

In above JSON example represent student data that means here Student is the JSON object and the Sid, Firstname, lastname, Contact no is the properties of Student object.

A basic JSON object is represented by Key-Value pair.

Here we show you some rules of JSON object like:

Its must start with ‘{‘ and end with ‘}’.

key field are included in double quotation’s.

value are represented by colon ‘:’.

JSON key-value pairs are separated by a comma “,”.

Values can be of any data type like String, Integer, Boolean etc.

 

JSON Array

A JSON Array means an ordered collection of values. It is surrounded by square braces i.e. [] which is calls index in array, and values are comma-delimited.

{ “month” : [ “january”, “february”, “march” ] }

 

Let’s have a look at a sample JSON with an Array. We will use the same Student object that we used earlier. We will add another property like “Branch”. An student can have different branch like Computer, IT, Mechanical and many more. So, in this case, we can use an array to offer a better way to record multiple Branch values.

{

“sid”          : “01”,

“Firstname”    : “codecrew”,

“lastname”     : “infotech”,

“Contact no”   : “1234567890”,

“Branch”       : [“Computer”, “IT”, “Mechanical”]

}

value of array will be separated by comma,

value must store between “[]” them.

 

in JSON, you can create nested JSON

Once we have added the car key in the Student JSON, we can then pass the value directly to the Car JSON.

{

“sid”          : “01”,

“Firstname”    : “codecrew”,

“Lastname”     : “infotech”,

“Contact no”   : “1234567890”,

“Branch”       : [“Computer”, “IT”, “Mechanical”]

“Car” : {

“Make&Model”: “Hyundai Creta”,

“MakeYear”: 2022,

“Color”: “White”,

“Type”: “Hatchback”,

}

}

 

 

Let’s assume a situation where there are multiple students, so we will have to create a JSON that can hold the data for several student.

[{

“sid”          : 01,

“FirstName”    : “codecrew”,

“LastName”     : “infotech”,

“Contact no”   : “1234567890”,

“Branch”       : [“Computer”, “IT”, “Mechanical”],

“Car” : {

“Make&Model”: “Hyundai Creta”,

“MakeYear”: 2022,

“Color”: “White”,

“Type”: “Hatchback”,

}

},

{

“sid”: 02,

“FirstName”: “zebel”,

“LastName”: “infotech”,

“Contact no”: “9876543212”,

        “Branch” : [“Computer”, “IT”, “Mechanical”],

“Car” : {

“Make&Model”: “Hyundai civic”,

“MakeYear”: 2022,

“Color”: “grey”,

“Type”: “Sedan”,

}

}]

 

 

 

From the same category