JSON

viswatech
5 min readMay 14, 2022

--

JSON

JSON is an acronym for JavaScript Object Notation, is an open standard format, which is lightweight and text-based, designed explicitly for human-readable data interchange. It is a language-independent data format. It supports almost every kind of language, framework, and library.

In the early 2000s, JSON was initially specified by Douglas Crockford. In 2013, JSON was standardized as ECMA-404, and RCF 8259 was published in 2017.

JSON is an open standard for exchanging data on the web. It supports data structures like objects and arrays. So, it is easy to write and read data from JSON.

Read More

In JSON, data is represented in key-value pairs, and curly braces hold objects, where a colon is followed after each name. The comma is used to separate key-value pairs. Square brackets are used to hold arrays, where each value is comma-separated.

What is JSON

  • JSON stands for JavaScript Object Notation.
  • JSON is an open standard data-interchange format.
  • JSON is lightweight and self-describing.
  • JSON originated from JavaScript.
  • JSON is easy to read and write.
  • JSON is language independent.
  • JSON supports data structures such as arrays and objects.

Features of JSON

  • Simplicity
  • Openness
  • Self-Describing
  • Internationalization
  • Extensibility
  • Interoperability

Why do we use JSON?

Since JSON is an easy-to-use, lightweight language data interchange format in comparison to other available options, it can be used for API integration. Following are the advantages of JSON:

  • Less Verbose: In contrast to XML, JSON follows a compact style to improve its users’ readability. While working with a complex system, JSON tends to make substantial enhancements.
  • Faster: The JSON parsing process is faster than that of the XML because the DOM manipulation library in XML requires extra memory for handling large XML files. However, JSON requires less data that ultimately results in reducing the cost and increasing the parsing speed.
  • Readable: The JSON structure is easily readable and straightforward. Regardless of the programming language that you are using, you can easily map the domain objects.

Read More

  • Structured Data: In JSON, a map data structure is used, whereas XML follows a tree structure. The key-value pairs limit the task but facilitate the predictive and easily understandable model.

JSON Data Types

Following are the most commonly used JSON data types.

· String

· Number

· Boolean

· Null

JSON Objects

In JSON, objects refer to dictionaries, which are enclosed in curly brackets, i.e., { }. These objects are written in key/value pairs, where the key has to be a string and values have to be a valid JSON data type such as string, number, object, Boolean or null. Here the key and values are separated by a colon, and a comma separates each key/value pair.

1. {“name” : “Jack”, “employeeid” : 001, “present” : false}

JSON Arrays

In JSON, arrays can be understood as a list of objects, which are mainly enclosed in square brackets [ ]. An array value can be a string, number, object, array, boolean or null.

For example:

1. [{

2. “PizzaName” : “Country Feast”,

3. “Base” : “Cheese burst”,

4. “Toppings” : [“Jalepenos”, “Black Olives”, “Extra cheese”, “Sausages”, “Cherry tomatoes”],

5. “Spicy” : “yes”,

6. “Veg” : “yes”

7. },

8.

9. {

10. “PizzaName” : “Veggie Paradise”,

11. “Base” : “Thin crust”,

12. “Toppings” : [“Jalepenos”, “Black Olives”, “Grilled Mushrooms”, “Onions”, “Cherry tomatoes”],

13. “Spicy” : “yes”,

14. “Veg” : “yes”

15. }

16. ]

In the above example, the object “Pizza” is an array. It contains five objects, i.e., PizzaName, Base, Toppings, Spicy, and Veg.

Output:

JSON Vs XML

JSON stands for JavaScript Object Notation, whereas XML stands for Extensive Markup Language. Nowadays, JSON and XML are widely used as data interchange formats, and both have been acquired by applications as a technique to store structured data.

JSON vs XML

Before knowing about the differences between JSON and XML, we should be aware of the definition of json and xml.

What is json?

JSON stands for JavaScript object notation. JSON has been derived from javascript, where javascript is a programming language. It was originally created to hold the structured data that could be used in javascript. JSON became so popular that it is used for data for all kinds of applications. It is the most popular way of sending the data for Web APIs.

Read More

Basic data types supported by json are:

  • Strings: Characters that are enclosed in single or double quotation marks.
  • Number: A number could be integer or decimal, positive or negative.
  • Booleans: The Boolean value could be either true or false without any quotation marks.
  • Null: Here, null means nothing without any quotation marks.

In addition to basic data types, json has arrays and objects.

A Sports and FIFA Sever Video

Arrays

Arrays are the lists that are represented by the square brackets, and the values have commas in between them. They can contain mix data types, i.e., a single array can have strings, Boolean, numbers.

For example:

Example 1: [1, 2, 7.8, 5, 9, 10];

Example 2: [“red”, “yellow”, “green”];

Example 3: [8, “hello”, null, true];

In the above, example 1 is an array of numbers, example 2 is an array of strings, and example 3 is an array of mix data types.

Objects

Objects are JSON dictionaries that are enclosed in curly brackets. In objects, keys and values are separated by a colon ‘:’, pairs are separated by comma. Keys and values can be of any type, but the most common type for the keys is a string.

For example: {“red” : 1, “yellow” : 2, “green” : 3};

Nesting

Nesting involves keeping the arrays and objects inside of each other. We can put the arrays inside objects, objects inside arrays, arrays inside arrays, etc. We can say that json file is a big object with lots of objects and arrays inside.

Example:

1. {

2. “song” :

3. {

4. “title” : “Hey Dude”;

5. “artist”: “The Beatles”;

6. “musicians”: [“John Lennon”, “Paul McCratney”, “Ringo Starr”];

7. }

8. }

In the above code, the song starts with a curly bracket. Therefore, a song is an object. It contains three key-value pairs wherein title, artist and musicians are the keys.’

What is XML?

XML stands for an extensible markup language. It is like HTML, where HTML stands for Hypertext Markup language. HTML is used for creating websites, whereas XML can be used for any kind of structured data.

XML has two ways of handling data, i.e., Tags and Attributes. The tags work as HTML. The start tags start with the <_> and end with the </_>. The start and end tags must match. The names must only be letters, numbers, and underscore, and the tag name must start with a letter only.

Read More

For example:

<title> Hello World </title>

Nested Tags

When we put the tag inside of another tag that creates the nested data.

For example:

1. <color>

2. <red> 1 </red>

3. <yellow> 2 </yellow>

4. <green> 3 </green>

5. </color>

As we can observe in the above code that inside the color tag, we have three more tags, i.e., red, yellow, and green.

Similarities between the json and XML.

  • Self-describing: Both json and xml are self-describing as both xml data and json data are human-readable text.
  • Hierarchical: Both json and xml support hierarchical structure. Here hierarchical means that the values within values.
  • Data interchange format: JSON and XML can be used as data interchange formats by many different programming languages.
  • Parse: Both the formats can be easily parsed.
  • Retrieve: Both formats can be retrieved by using HTTP requests. The methods used for retrieving the data are GET, PUT, POST.

--

--