What is JSON?
In this lesson, you will learn what JSON is, why every major software company uses it, and why it is essential for modern AI engineering.
1. Why Does JSON Exist?
The Real-World Problem
Imagine you build an online shopping website:
- Your database and backend logic are written in Python.
- The mobile app on the user's phone is written in Swift (iOS) or Kotlin (Android).
- The web browser UI is written in JavaScript.
If Python sends a raw Python dictionary ({'name': 'Laptop'}), JavaScript and Swift will crash because they do not understand Python's internal memory format.
To solve this, developers agreed on a lightweight, plain-text standard called JSON (JavaScript Object Notation).
[ Python Backend ] ──( sends JSON text )──> [ Mobile App / Web Browser ]
2. Beginner Mental Model: The Courier Package
- When you want to send a gift to a friend in another city, you don't send individual loose items.
- You pack the items into a standardized cardboard box with a label, tape it, and hand it to the courier.
- The receiver opens the box and takes out the items.
In programming:
- Python Dictionary: The items on your table.
- JSON: The standardized text package sent over the internet.
3. Python Dictionary vs JSON: Key Differences
While JSON looks very similar to a Python dictionary, there are strict syntax differences you must know:
| Feature | Python Dictionary | JSON (Text Standard) |
|---|---|---|
| Quotes for Keys | Can use 'single' or "double" quotes | Strictly "double quotes" only |
| Booleans | True / False (Capitalized) | true / false (All lowercase) |
| Empty / None | None | null |
| Data Type | In-memory Python object (dict) | Plain text string (str) |
# In Python:
user_dict = {
'name': 'Rahul',
'is_active': True,
'score': None
}
# Equivalent JSON Text:
# {
# "name": "Rahul",
# "is_active": true,
# "score": null
# }
4. Common Beginner Mistakes
In Python, writing {'name': 'Sai'} is completely valid.
In JSON, single quotes {'name': 'Sai'} will cause a JSONDecodeError! Always use double quotes {"name": "Sai"}.
Quick Summary
- JSON Definition: JavaScript Object Notation is a lightweight, human-readable text standard for data interchange.
- Double Quote Rule: JSON strictly requires double quotation marks (
"key": "value") for all keys and strings. Single quotes are invalid. - Data Type Mappings:
true->True,false->False,null->None, Array[]->list, Object{}->dict.
What's Next?
Let's dive deeper into syntax rules, nesting, and data hierarchy in JSON Structure & Data Types!