AXS TXTAXS TXT

JSON

JSON (JavaScript Object Notation) is a simple text format for structured data, built from key–value pairs and arrays. It's the most common format for APIs and config files because it's easy for both people and machines to read.

Valid JSON must follow strict rules — double-quoted keys, no trailing commas — which is why a formatter that also validates is handy.

Use the JSON formatter to pretty-print, minify and validate JSON.

What JSON is

JavaScript Object Notation is a text format for structured data, built from six things: objects of key-value pairs in braces, arrays in brackets, strings in double quotes, numbers, the literals true and false, and null. That is the entire specification, which is precisely why it won — it is small enough to implement in an afternoon and readable enough to debug by eye.

Why it fails to parse

A short list covers nearly every error. A trailing comma after the last element, which JavaScript tolerates in source and JSON does not. Single quotes instead of double — JSON requires double, always, for keys and strings alike. Unquoted keys, valid in a JavaScript object literal and invalid in JSON. Comments, which JSON has no concept of at all. And smart quotes substituted by a word processor, which look almost identical to straight ones and are much the hardest of the set to spot. A formatter helps mainly by showing where the parser gave up, which is normally a character or two after the actual mistake.

JSON is not JavaScript

Despite the name, JSON is a strict subset of JavaScript's object syntax with deliberate differences. It has no functions, no variables, no expressions, no dates and no comments. A date in JSON is a string by convention — most often ISO 8601 — and the two ends have to agree on interpreting it, which is a routine source of timezone bugs.

Numbers deserve caution

JSON does not distinguish integers from floats, and does not specify a precision. Most parsers read numbers as IEEE 754 doubles, which represent integers exactly only up to about 9 quadrillion. Large identifiers — database keys, Twitter-style snowflake IDs — silently lose their last digits when passed as JSON numbers. The standard fix is to transmit them as strings.

JSON and CSV

They describe different shapes. CSV is a flat grid of rows and columns; JSON is a tree that nests freely. Flattening JSON to CSV means deciding what to do with nested structures, usually by joining path segments into column names. Going the other way is unambiguous, since every row becomes an object with the header row as its keys.

Try JSON Formatter

Open JSON Formatter