ENRU

JSON guides

Updated

Guides to the parts of JSON that trip people up: what a JSON file is and how to format it, big numbers that change value, keys that change places, comments that aren’t allowed, one value per line, and YAML. Each one shows what real parsers print and how to get the result you meant.

All JSON guides

GuideWhat it answers
What is JSON and how to open a .json fileWhat the format is, what a .json file holds and how to open one on Windows, macOS, Linux, Android, iPhone or in a browser.
How to pretty print JSONFormatting JSON in Python, jq, JavaScript, Go and PowerShell, in VS Code, Notepad++, IntelliJ and Sublime Text, or online.
Big numbers in JSON: BigInt, precision and JSON.parseWhy JSON.parse rounds 12345678901234567890 and drops the zero in 1.10, what “Do not know how to serialize a BigInt” means, and how to keep numbers exact in JavaScript, Python, Go and Java.
JSON key order: why numeric keys jump aheadWhy JavaScript moves numeric keys to the front, why sorting tools put "10" before "2", and when order matters.
Can JSON have comments? JSONC, JSON5 and workaroundsWhy JSON has no comments, what JSONC and JSON5 allow, and how to annotate a file or strip comments before parsing.
JSON Lines (NDJSON): what it is and how to read itOne JSON value per line, why json.load fails with “Extra data”, and how to read and write such files in Python, JavaScript, Go and jq.
JSON vs YAML: differences, traps and when to use eachSyntax, comments, anchors, the YAML 1.1 Norway problem, numbers, and when to choose which format.

JSON errors and tools

Looking at a specific error message, such as “Unexpected token” or “Expecting value”? The JSON errors reference explains each one by cause, with the exact text from each parser. To check a document now, use the Validator; to format it, the Formatter.

JSON guides FAQ

Which JSON rules do these guides follow?

Strict JSON as RFC 8259 defines it, the same rules the Validator applies. JSONC, JSON5 and JSON Lines are covered as separate formats, with what each one adds.

Why does the same JSON come out differently in different tools?

Most tools parse the text into values and print the values back. On the way numbers become doubles, objects lose their key order and comments become errors. The guides show where each of these happens and how to avoid it.

Can I run the examples myself?

Yes. Each example says which parser and version printed the output, so you can repeat it with Node.js, Python, Go, Java or jq, or paste the same JSON into the Formatter to compare.