-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
JS Basics
JS Variables & Operators
JS Data Types & Conversion
JS Numbers & Math
JS Strings
JS Dates
JS Arrays
JS Control Flow
JS Loops & Iteration
JS Functions
JS Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Web APIs
Web API Intro
Web Validation API
Web History API
Web Storage API
Web Worker API
Web Fetch API
Web Geolocation API
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Graphics & Charts
If you’ve ever shared data between a website and a server, you’ve probably come across something called JSON. It’s everywhere — in web apps, APIs, mobile apps, and even databases. JSON is simple, lightweight, and easy to read, which is why it has become one of the most popular data formats in the world.
In this tutorial, we’ll understand what JSON is, why it’s so widely used, and how it helps web developers send and receive data efficiently.
JSON stands for JavaScript Object Notation.
It’s a text-based format used to store and exchange data between a client (like a web browser) and a server.
In simple terms, JSON is a way to represent data just like you would write an object in JavaScript, but in plain text so it can be easily shared across different systems.
Here’s a simple example of JSON data:
{
"name": "Vicky",
"age": 28,
"city": "Mumbai"
}
This looks almost like a JavaScript object, right? That’s because JSON was originally inspired by JavaScript’s object syntax.
But the good part is — JSON isn’t limited to JavaScript anymore. It’s supported by almost all modern programming languages, such as PHP, Python, Java, C#, and many others.
Before JSON became popular, another format called XML (Extensible Markup Language) was widely used for data exchange.
While XML was powerful, it was also verbose (too much syntax) and harder to read.
For example, here’s how you’d represent the same data in XML:
<person>
<name>Vicky</name>
<age>28</age>
<city>Mumbai</city>
</person>
Now compare it with the JSON version again:
{
"name": "Vicky",
"age": 28,
"city": "Mumbai"
}
The JSON format is shorter, cleaner, and easier to read — and that’s exactly why it became the preferred format for web data communication.
Here are the main reasons developers love JSON:
Lightweight and Fast
JSON doesn’t include extra tags or attributes like XML. That means less data to send and faster communication.
Human-Readable
JSON looks simple — even beginners can understand it at a glance. It’s written in plain text, so it’s easy to edit and debug.
Language-Independent
Even though JSON originated from JavaScript, it’s now supported by nearly every language.
Every major programming language can easily parse (read) and generate (write) JSON.
Structured and Organized
JSON supports nested objects and arrays, allowing you to store complex data in a clean and organized structure.
Easy to Integrate with APIs
Most web APIs (like Google Maps API, OpenWeather API, etc.) use JSON to send and receive data. This makes integration smooth and efficient.
You’ll find JSON in almost every corner of modern web development. Some common uses include:
APIs — When a web application fetches or sends data to a server, JSON is usually the format used.
Configuration Files — Many tools and frameworks use JSON to store settings (for example, package.json
in Node.js).
Databases — NoSQL databases like MongoDB store data in a JSON-like format called BSON.
Data Storage — Small apps sometimes store data in JSON files instead of full databases.
Web Services — RESTful APIs commonly send JSON responses to clients.
Example:
When you sign in to a website, your login information might be sent as JSON like this:
{
"username": "vicky123",
"password": "mypassword"
}
And the server might respond with JSON too:
{
"status": "success",
"userId": 101,
"message": "Welcome Vicky!"
}
This exchange happens quickly and smoothly because JSON is lightweight and universal.
A JSON file or data structure is built using two main types of components:
Key/Value Pairs
Arrays
The basic building block of JSON is a key/value pair, just like in JavaScript objects.
A key is always a string written inside double quotes (" "
).
A value can be:
A string
A number
A boolean (true
or false
)
An object (another JSON)
An array
Or null
Example:
{
"name": "Vicky",
"age": 28,
"isDeveloper": true
}
Here:
"name"
is the key, and "Vicky"
is the value.
"age"
is the key, and 28
is the value.
"isDeveloper"
is the key, and true
is the value.
Arrays are used to store multiple values in a single variable.
In JSON, arrays are written inside square brackets []
.
Example:
{
"students": ["Vicky", "Sanjana", "Rohit"]
}
You can also store multiple objects inside an array:
{
"employees": [
{ "name": "Vicky", "role": "Developer" },
{ "name": "Sanjana", "role": "Designer" }
]
}
This makes JSON great for representing lists of data.
JSON has very strict syntax rules. Even a small mistake (like missing a quote or comma) can break the entire file.
Here are the key rules:
Data is written in key/value pairs.
Keys must be in double quotes.
Values can be strings, numbers, objects, arrays, booleans, or null
.
Strings must be in double quotes.
No trailing commas (the last item in an object or array cannot have a comma after it).
JSON data must always start and end with curly braces {}
if it’s an object, or square brackets []
if it’s an array.
Example of valid JSON:
{
"id": 1,
"name": "Vicky",
"skills": ["HTML", "CSS", "JavaScript"],
"active": true
}
JSON files are saved with the extension .json.
For example: data.json
You can open and edit these files in any text editor like VS Code, Notepad++, or Sublime Text.
When you view a JSON file, it’s always plain text — that’s what makes it so versatile and easy to share.
Let’s quickly summarize why JSON is preferred over other data formats:
Feature | JSON | XML |
---|---|---|
Readability | Easy and short | Long and complex |
Data Size | Compact | Larger |
Syntax | Simple (key-value) | Verbose (tags) |
Parsing Speed | Fast | Slower |
Supported Languages | Almost all | Almost all |
Best For | APIs and web data | Older enterprise systems |
Clearly, JSON wins in most cases, especially in web and app development.
Let’s say your website shows user profiles. When the browser requests data from the server, it might receive something like this:
{
"users": [
{
"name": "Vicky",
"email": "vicky@example.com",
"role": "Developer"
},
{
"name": "Sanjana",
"email": "sanjana@example.com",
"role": "Designer"
}
]
}
Now your front-end JavaScript code can easily read this JSON, display it on the webpage, or even update it dynamically.
JSON stands for JavaScript Object Notation.
It’s a lightweight, text-based format used for storing and transferring data.
JSON data is structured as key/value pairs and arrays.
It’s easy to read, easy to write, and supported across almost every language.
JSON is mostly used in APIs, configurations, and databases.
In short, JSON is the bridge that allows your web browser and server to communicate smoothly — and once you master it, you’ll use it everywhere in web development.
Create a JSON object that stores your personal details like name, age, city, and profession. Print the value of each key using JavaScript.
Write a JSON object to store details of 3 students (name, roll number, marks). Access the marks of the second student and display it.
Convert the following JavaScript object into a JSON string using JSON.stringify()
:
let user = { name: "Vicky", age: 25, city: "Delhi" };
Convert this JSON string into a JavaScript object using JSON.parse()
:
'{ "name": "Sanjana", "course": "Web Development" }'
Create a JSON array containing 5 employee names. Write JavaScript code to print each name using a loop.
You have a JSON object of products:
{
"products": [
{ "id": 1, "name": "Laptop", "price": 55000 },
{ "id": 2, "name": "Mouse", "price": 700 }
]
}
Write JavaScript code to print the total price of both products.
Create a JSON object to represent a book with keys: title, author, year, and genres (array). Display the author’s name and first genre.
Write a JSON object for a car that includes model, color, fuel type, and an array of service dates. Print the last service date.
Given this JSON data:
{
"students": [
{ "name": "Vrinda", "score": 88 },
{ "name": "Sanjana", "score": 95 },
{ "name": "Vicky", "score": 72 }
]
}
Write JavaScript code to find and print the student with the highest score.
Write a JSON object that contains user login information (username, password, isActive). Convert it to a string using JSON.stringify()
, then parse it back to an object and print only the username.
JS Basics
JS Variables & Operators
JS Data Types & Conversion
JS Numbers & Math
JS Strings
JS Dates
JS Arrays
JS Control Flow
JS Loops & Iteration
JS Functions
JS Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Web APIs
Web API Intro
Web Validation API
Web History API
Web Storage API
Web Worker API
Web Fetch API
Web Geolocation API
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Graphics & Charts