What is JSON?
JSON (JavaScript Object Notation, RFC 8259) is a plain-text format for structured data built from objects, arrays and a handful of value types. It is easy for humans to read and every mainstream language can parse it, so it is the default format for web APIs and for config files such as package.json.
| Type | Example |
|---|---|
| String | "Alice" (double quotes only) |
| Number | 30, 3.14, -1e10 |
| Boolean | true, false |
| Null | null |
| Array | [1, 2, 3] |
| Object | {"a": 1} |
Formatting {"name":"Alice","age":30,"tags":["admin","dev"]} with 2-space indentation gives:
{
"name": "Alice",
"age": 30,
"tags": [
"admin",
"dev"
]
}
Common JSON syntax errors
| Problem | Invalid | Valid |
|---|---|---|
| Trailing comma | {"a": 1,} | {"a": 1} |
| Single quotes | {'a': 1} | {"a": 1} |
| Unquoted key | {a: 1} | {"a": 1} |
| Comments | // note | Not allowed in JSON |
| undefined / NaN | {"a": undefined} | {"a": null} |
Trailing commas and comments are accepted by JavaScript object literals and by “JSON with comments” formats such as JSONC or JSON5, but not by a standard JSON parser.
Format JSON in code and on the command line
| Tool | Pretty-print | Minify |
|---|---|---|
| jq | jq . data.json | jq -c . data.json |
| Python | python3 -m json.tool data.json | python3 -m json.tool --compact data.json |
| JavaScript | JSON.stringify(obj, null, 2) | JSON.stringify(obj) |
| PHP | json_encode($v, JSON_PRETTY_PRINT) | json_encode($v) |
Frequently asked questions
Why do the last digits of a large number change?
JavaScript numbers are 64-bit floating point and represent integers exactly only up to 253 − 1 (9007199254740991). A larger integer is rounded when parsed — 9007199254740993 becomes 9007199254740992. If you need exact large IDs, send them as strings.
What is “Sort keys” for?
It orders object keys alphabetically at every level of nesting. Sorting two documents before comparing them makes a diff show only real differences, not differences in key order.
Can it decode \uXXXX escapes?
Yes. Formatting parses the JSON, so escapes such as é are shown as the actual character (é). To convert escapes in plain text, use the Unicode escape tool.
Is it safe to paste an API response?
The JSON is parsed and formatted in your browser and is not sent to any server. Still, be careful where you paste tokens or personal data in general.