JSON (JavaScript Object Notation) is a text format for storing and sending structured data. It's lightweight, human-readable, and understood by virtually every programming language. When a website loads your feed, a weather app gets current temperature, or an app saves your settings — JSON is almost certainly involved in the background.
What JSON Looks Like
``json { "name": "Ahmed Khan", "age": 28, "city": "Lahore", "skills": ["SEO", "Web Design", "Python"], "active": true, "salary": null } ``
The Building Blocks
Key-value pairs: every piece of data has a name (key) and a value.
"name": "Ahmed Khan"— the key isname, the value is the stringAhmed Khan.
Data types in JSON:
| Type | Example | Notes |
|---|---|---|
| String | "Hello" | Always in double quotes |
| Number | 42 or 3.14 | No quotes |
| Boolean | true or false | Lowercase, no quotes |
| Null | null | Represents "no value" |
| Array | ["a", "b", "c"] | Ordered list in square brackets |
| Object | {"key": "value"} | Nested data in curly braces |
Nested JSON
Objects can contain other objects and arrays:
``json { "user": { "name": "Sara", "address": { "city": "Karachi", "country": "Pakistan" } }, "scores": [95, 88, 72] } ``
Common JSON Errors
- Missing comma between items in an object or array.
- Single quotes instead of double quotes on strings or keys.
- Trailing comma after the last item (valid in JavaScript but not in JSON).
- Unquoted key:
{name: "Sara"}is wrong;{"name": "Sara"}is correct.
Reading and Formatting JSON
Raw JSON from an API or file is often in one long line, making it hard to read. The JSON Formatter takes any JSON and displays it with indentation. It also validates the JSON and shows exactly where errors are if it can't parse it — see how to fix invalid JSON errors for the most common ones.
JSON in API Responses
When you call a modern web API, the response almost always comes back as JSON. Understanding JSON lets you work with these responses: parse them in code, read them in an API testing tool like Postman, or debug unexpected values. Tools that work with APIs — Laravel, React, Python's requests library — all have built-in JSON parsers that convert JSON text into native data structures automatically. For when JSON is malformed and the parser throws an error, the debugging process is covered in how to fix invalid JSON errors.
JSON vs Python Dictionary
JSON looks identical to a Python dictionary in simple cases. The key difference: JSON is text (a string), while a Python dict is a data structure in memory. json.dumps() converts a Python dict to JSON text; json.loads() converts JSON text back to a Python dict. In JavaScript, JSON.stringify() and JSON.parse() do the same. The JSON Formatter is the quick alternative when you need to view or validate JSON without writing code.