What Is JSON? β Definition and How It Works
Learn what JSON is, its six value types, how it is parsed and serialised, and the edge cases that break pipelines β numbers, duplicates, and encoding.
JSON is a text format for structured data. It is the default payload format for web APIs because it maps cleanly onto the data structures every mainstream language already has.
1. What Is JSON?
JavaScript Object Notation is a syntax for representing objects, arrays, and primitives as text.
- Key idea: a minimal grammar that both people and parsers read easily.
- Mechanism: nested key-value objects and ordered arrays, serialised as UTF-8 text.
- Goal: interchange between systems written in different languages.
Example
{
"query": "web scraping api",
"results": 8,
"cached": false,
"tags": ["search", "serp"],
"next_page": null
}
2. The Six Value Types
| Type | Notes |
|---|---|
| Object | Unordered key-value pairs; keys must be strings in double quotes |
| Array | Ordered list, values may be of mixed type |
| String | Double-quoted, with backslash escapes |
| Number | Decimal, optional exponent; no distinction between integer and float |
| Boolean | true or false, lowercase |
| Null | null, lowercase |
There is no date type, no comment syntax, and no trailing commas. Dates travel as strings, conventionally in ISO 8601.
3. Parsing and Serialising
Every mainstream language ships JSON support: a parse function turning text into native structures, and a serialise function doing the reverse. The mapping is nearly universal β objects to dictionaries or maps, arrays to lists, and the primitives to their native equivalents.
Round-tripping is not always lossless. Key order, number precision, and unrepresentable values such as infinity or a native date type can all change on the way through.
4. The Edge Cases That Bite
- Large integers. JSON numbers have no defined precision limit, but many parsers use double-precision floats. Identifiers beyond about 2^53 silently lose their last digits. Send them as strings.
- Duplicate keys. The grammar permits them; parsers usually keep the last. Two implementations can disagree about the same document.
- Encoding. JSON text is UTF-8 by default. A byte-order mark at the start makes strict parsers reject the document.
- Empty versus missing.
null,"", and an absent key are three different things, and treating them as one is a common source of silent data loss.
5. JSON in Practice for Data Work
Two conventions matter when JSON carries collected data.
- JSON Lines β one complete JSON object per line, so a file can be streamed and appended without re-reading. Preferred for large collections over one enormous array.
- Embedded JSON in HTML β many pages carry their data in a script tag as JSON, which is often cleaner and more stable to read than the rendered markup.
6. Common Misconceptions
- "JSON is JavaScript." It is a subset of JavaScript's object literal syntax, and a separate specification.
- "Objects preserve key order." The specification treats objects as unordered; most implementations preserve insertion order, but relying on it is unsafe across systems.
- "Any JSON parses everywhere." Comments, trailing commas, and single quotes are common extensions that strict parsers reject.
- "Numbers are safe." Precision loss on large integers is the single most common silent JSON bug.
7. Summary
JSON is a small, strict text format with six value types that maps directly onto native structures in every mainstream language, which is why it dominates web APIs.
Its sharp edges are all about implicit assumptions β integer precision, duplicate keys, encoding, and the difference between null, empty, and absent. Handling those four explicitly removes most JSON-related data loss.