JSON (JavaScript Object Notation) is the plain-text format most web APIs, configuration files and data exports use. It is small enough to learn in an afternoon, yet its strictness trips people up constantly. This guide covers the rules, the traps and the tools around it; every claim was run in Node and Python.
The six value types
| Type | Example | Notes |
|---|---|---|
| Object | {"a": 1} |
Unordered key and value pairs; keys are always strings in double quotes |
| Array | [1, 2, 3] |
Ordered list of any values |
| String | "hello" |
Double quotes only; escape with a backslash, \u00e9 for Unicode |
| Number | -12.5e3 |
No leading zeros, no hex, no NaN or Infinity |
| Boolean | true, false |
Lower case only |
| null | null |
An explicit "no value" |
There is no date type: send dates as ISO 8601 strings such as 2026-10-03T14:30:05Z. Compare it with other formats in JSON, YAML and XML.
Why a parse fails
JSON is stricter than JavaScript object syntax. These all fail to parse in both Node and Python:
- a trailing comma:
{"a":1,} - single quotes:
{'a':1} - a leading zero:
{"a":01} - a comment:
// notebefore the data
NaN is also invalid in the standard, and Node rejects it, but Python's json module accepts NaN by default unless you pass allow_nan=False or a parse_constant hook, so data that works in one language can fail in another. Paste suspect text into the JSON Viewer or JSON Editor to see exactly where it breaks, and fix it in the JSON Formatter & Prettifier.
Traps that look like valid JSON
- Big integers. JavaScript stores numbers as 64-bit floats, so
{"id": 9007199254740993}parses to9007199254740992in Node (the limit for exact integers is 9007199254740991). Python keeps the full value. Send large identifiers as strings. - Duplicate keys. The standard leaves them undefined; Node and Python both keep the last one, so
{"a":1,"a":2}becomesa = 2. - Key order. JSON objects are unordered. Node puts integer-like keys first (
{"b":1,"2":1,"a":1,"1":1}gives the order1, 2, b, a), while Python keeps insertion order. Never depend on it.
Pretty or minified
Whitespace is optional. The same small object is 53 characters pretty-printed and 31 minified, 42% smaller; use the JSON Minifier & Compressor for transfer and the formatter for reading. Gzip shrinks both much further.
Querying with JSONPath
JSONPath addresses values inside a document, the way XPath does for XML. Given a store with three books priced 8.95, 12.99 and 22.99:
| Query | Result |
|---|---|
$.store.book[*].title |
A, B, C |
$.store.book[0].title |
A |
$.store.book[?(@.price < 10)].title |
A |
$..price |
8.95, 12.99, 22.99 |
$ is the root, . steps into a key, [*] takes every element, [?()] filters and .. searches at any depth. Try your own in the JSONPath Tester. JSON Schema is the companion for validating structure: for example {"type": "object", "required": ["id", "name"], "properties": {"id": {"type": "integer"}, "name": {"type": "string"}}} requires an integer id and a string name.
Converting JSON
- To TypeScript:
{"id": 1, "name": "Ada", "tags": ["a", "b"], "address": {"city": "X", "zip": null}}becomes
export interface User {
id: number;
name: string;
tags: string[];
address: Address;
}
export interface Address {
city: string;
zip: null;
}
with the JSON to TypeScript.
- To a table or spreadsheet: an array of objects maps naturally to rows, with the keys as the header. [{"id":1,"name":"Ada"},{"id":2,"name":"Alan"}] as TSV is a header line id, tab, name followed by one line per object. Use JSON to TSV Converter, TSV to JSON Converter, JSON to HTML Table Converter or JSON to Text Converter; for other formats see JSON to XML Converter, CSV to TSV Converter, TSV to CSV Converter and Excel to CSV Converter.
- Comparing two documents: the JSON Diff Checker lists what was added, removed and changed.
- Test data: the Mock / Fake JSON Data Generator makes realistic sample rows from a seed.
Common mistakes
- Treating JSON as JavaScript. Single quotes, comments and trailing commas are not allowed.
- Using numbers for identifiers. Long IDs lose precision in JavaScript; use strings.
- Relying on key order. Use an array when order matters.
- Hand-building JSON with string concatenation. Use a serializer, which escapes quotes and Unicode correctly.