Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
What is JSON
2.1.
Features of JSON
2.2.
Different data types in JSON
2.3.
JSON object and JSON arrays
3.
Why use JSON
4.
Frequently Asked Question
5.
Key Takeaways
Last Updated: Mar 27, 2024

JSON introduction and Syntax

Author Sunil Sharma
0 upvote

Introduction

 

JSON, also known as javascript object notation, is a lightweight, text-based open standard format designed for human-readable data interchange. This format is not dependent on languages, and it is supportable in every type of library, language, and framework.

In this blog, we will see what JSON is, why we use JSON and JSON syntax.

 

What is JSON

Douglas Crockford initially specified JSON. JSON was standardized as ECMA-404 in 2013. In JSON, we represent data in key-value pairs and hold objects in curly braces, and a colon is followed after every name. We use comma to separate key-value pairs. We use square brackets to hold arrays in which each value is comma-separated.

 

Features of JSON

 

  1. JSON does not depend on language.
  2. JSON is lightweight.
  3. JSON is self-describing.
  4. JSON is known for its simplicity.
  5. JSON is extensible and interoperable.

 

Different data types in JSON

 

Null- It is an empty value.

 

Boolean- It’s valued can be either true or false;

Example- true.

 

String- String is written in double quotes.  The string can contain numbers, alphanumeric and special characters.

Example- “Hello,” “123”, “xyz_123”.

 

Number- It represents the numeric value.

Example- 505, 75843838.

 

JSON object and JSON arrays

 

JSON object- 

      {
		"state" : "Haryana",
 		"pincode" : 123,
 		"developed" : true
      }  

 

 

JSON array-

[
	{  
		"state" : "Haryana",  
		"cities" : ["Panipat", "Karnal", "Faridabad", "Gurugram"],   
	},  
	{  
		"state" : "Rajasthan",    
		"cities" : ["Alwar", "Jaipur", "Jodhpur", "Bharatpur"],  
	}  
]  

 

Why use JSON

 

  • We can use JSON with modern programming languages.
  • Its primary purpose is to transmit data between a server and web applications.
  • By using JSON format, we can serialize and transfer structured data over the network connections.
  • We can fetch public data from API and Web services by using JSON format.
  • JSON is used in JavaScript-based applications, which includes browser extensions and websites.

 

 

Frequently Asked Question

 

How to convert a JSON text into an object?

Answer - We use the “eval” function to convert JSON text into an object.

 

What JSON. stringify do?

Answer-  JSON.stringify() is used to convert an object into a JSON text, and that JSON text has stored a string.

 

How to convert a string into a JSON Array?

Answer- First, you have to create a JSONObject object for every object and then add those objects into your JSON array.

 

Tell us about the MIME type of JSON.

Answer- “application/json” is the mime type for JSON.

 

Tell us about the file extension of JSON. 

Answer- File extension of JSON is .json.

 

Key Takeaways

This blog contains information about what JSON is, why it is useful, and its syntax.

If you are interested in JavaScript and want to become a great web developer, check out this amazing JavaScript course on web development.

 

Also, if you are preparing for interviews, visit this JavaScript interview question blog.

Happy Reading!

 

Live masterclass