What is JSON?
JSON stands for “JavaScript Object Notation” and is a lightweight format used for data exchange. JSON is easy for humans to read and write and is also quick for computers to process.
Why Use JSON?
JSON is commonly used for sharing data between applications. For example, when you need to send or receive data from a website to another application, JSON is an ideal format.
Key Features of JSON
- Simple and Lightweight: JSON has an easy-to-learn structure and, because of its small file size, can be transferred quickly.
- Language-Independent: JSON is supported by many programming languages like Python, Ruby, Java, and not just JavaScript.
- Key-Value Structure: Data is stored in
key: valuepairs.
Structure of JSON
A JSON file consists of two main structures:
Get Havanur Kara’s stories in your inbox
Join Medium for free to get updates from this writer.
Objects: Use curly braces {} and contain key-value pairs.
{
"name": "John",
"age": 25,
"city": "New York"
}Arrays: Use square brackets [] and contain multiple values.
[
{ "product": "Phone", "price": 1000 },
{ "product": "Laptop", "price": 2000 }
]JSON vs XML
In the past, XML (Extensible Markup Language) was widely used. However, JSON has become more popular due to its simpler structure. For instance:
- JSON: Takes up less space and is easier to read.
- XML: More complex and uses additional tags.
How to Use JSON?
JSON is often used to retrieve or send data through APIs. Here’s a simple example:
Reading JSON (Parse):
const jsonData = '{"name": "John", "age": 25}';
const obj = JSON.parse(jsonData);
console.log(obj.name); // JohnCreating JSON (Stringify):
const data = { name: "John", age: 25 };
const jsonData = JSON.stringify(data);
console.log(jsonData); // {"name":"John","age":25}Conclusion
JSON is a powerful tool that simplifies data sharing in modern applications. Its simple structure and broad support make it an essential part of the software development world.






