What is JSON?
- JSON stands for JavaScript Object Notation.
- It’s a lightweight, easy-to-read format used to store and exchange data.
- Both humans and computers can understand JSON easily.
- JSON is made up of key-value pairs organized inside curly braces
{}
.
Basic JSON Syntax
Element | Description | Example |
---|---|---|
Object | Unordered collection of key-value pairs. | { "name": "Alice" } |
Array | Ordered list of values. | [ "red", "green", "blue" ] |
Key (Name) | Always a string in double quotes. | "age" |
Value | Can be a string, number, object, array, true , false , or null . | "Alice" , 30 , true |
String | Text wrapped in double quotes. | "hello world" |
Number | Numeric value (integer or decimal). | 42 , 3.14 |
Boolean | true or false (no quotes). | true |
Null | Represents empty or no value. | null |
JSON Formatting Rules
- Data is inside curly braces
{}
for objects. - Key-value pairs are separated by commas.
- Keys and string values are enclosed in double quotes
""
. - Arrays use square brackets
[]
. - No trailing commas (commas after the last item) allowed.
- Whitespace and indentation are optional but improve readability.
Example: JSON Object
json{
"name": "Alice",
"age": 30,
"is_student": false,
"favorite_colors": ["red", "green", "blue"],
"address": {
"city": "New York",
"zip_code": "10001"
}
}
This JSON means:
- Name is “Alice”
- Age is 30
- Not a student
- Likes red, green, and blue colors
- Lives in New York, ZIP 10001
How to Read JSON
- Look for keys to understand what information is given.
- Values tell you the actual data.
- Arrays list multiple values in order.
- Nested objects group related data together.
Common JSON Use Cases
- Configuration files
- API responses
- Data exchange between web servers and clients
- Structured outputs from AI models like GPT-OSS-20B
Helpful Tips for Beginners
- Practice reading and writing simple JSON snippets.
- Use JSON viewers or text editors with JSON formatting support.
- Validate your JSON online with free tools like JSONLint.
- Remember keys must always be strings with double quotes.