Sitemap
Havanur Kara

Havanur Kara

What is JSON?

2 min readJan 4, 2025

--

Press enter or click to view image in full size

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

  1. Simple and Lightweight: JSON has an easy-to-learn structure and, because of its small file size, can be transferred quickly.
  2. Language-Independent: JSON is supported by many programming languages like Python, Ruby, Java, and not just JavaScript.
  3. Key-Value Structure: Data is stored in key: value pairs.

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); // John

Creating 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.

--

--