JSON (JavaScript Object Notation) Basics
JSON is a text-based, standard data format used for storing and transmitting data. While it originated from JavaScript object literal notation, it is now language-agnostic and universally used across programming platforms.
It is the de facto standard format for data exchange in modern web APIs.
1. JSON Structure
JSON builds data using two fundamental structures:
① Object
Represented by curly braces { }, an object is an unordered collection of key-value pairs. The key must always be a string.
{
"firstName": "John",
"lastName": "Doe",
"age": 45,
"isStudent": false
}
② Array
Represented by square brackets [ ], an array is an ordered list of values. These values can be any valid JSON type: string, number, boolean, object, or another array.
[
"Red",
"Green",
"Blue",
123
]
3. Nested Structure Example
JSON's flexibility comes from its ability to nest objects and arrays within each other.
{
"userID": 42,
"orders": [
{
"productName": "Keyboard",
"quantity": 1
},
{
"productName": "Monitor",
"quantity": 2
}
],
"totalItems": 3
}
2. Importance and Advantages
- Lightweight: JSON is minimal and less verbose than formats like XML, leading to smaller data sizes and faster transmission.
- Readability: It is easy for humans to read and write.
- Universal Compatibility: Almost all modern programming languages (Python, JavaScript, Java, etc.) have built-in functions to easily serialize (create) and parse (read) JSON data.