What a JSON formatter does
JSON — JavaScript Object Notation — is the default data format for web APIs. It is whitespace-insensitive, which is exactly why formatting matters: a server can send a 40 KB response as one unbroken line and it is perfectly valid, but no human can find the field they need in it. A JSON formatter parses that text into a real data structure and prints it back out with one value per line and indentation that mirrors the nesting, so the shape of the document becomes visible at a glance.
Because formatting requires parsing, it doubles as validation. If the text comes back formatted, it was syntactically valid JSON. If it does not, the tool reports where the parser gave up. That is the whole workflow: paste, press Format, and either read your data or read the error.
Format, minify and validate
Format expands the document for reading. Minify does the opposite — it strips every byte of optional whitespace, which is what you want for a response body, a config value squeezed into an environment variable, or a payload you are about to paste into the API tester's body field. Validate only parses without producing output, which is handy for a quick yes-or-no check on a very large document. Sort keys recursively alphabetises object keys, which makes two responses diffable when a server returns fields in an unstable order.
How JSON parsing actually fails
JSON is a deliberately tiny grammar, and most parse failures come from writing JavaScript rather than JSON. These are the ones that account for nearly every error you will hit:
| Written | Problem | Correct |
|---|---|---|
{"a":1,} | Trailing comma after the last member | {"a":1} |
{'a':1} | Single quotes are not valid JSON string delimiters | {"a":1} |
{a:1} | Object keys must be quoted strings | {"a":1} |
{"a":undefined} | undefined is not a JSON value | {"a":null} |
{"a":.5} | Numbers need a leading digit | {"a":0.5} |
{"a":01} | Leading zeros are not allowed | {"a":1} |
// note | JSON has no comment syntax at all | Remove it, or move it into a field |
{"a":NaN} | NaN and Infinity are not representable | null, or a string |
One error deserves special mention because it confuses people for hours:
Unexpected token < in JSON at position 0. That almost never means your JSON is broken.
It means the response was not JSON at all — you received an HTML error page, usually a
404 or a 500 rendered by a
proxy or framework. Check the status code and the Content-Type
response header before touching the parser.
Subtler pitfalls worth knowing
Numbers lose precision
JSON does not define a maximum number size, but JavaScript parses every number as a 64-bit float.
Any integer above 9,007,199,254,740,991 silently loses precision, so a 64-bit database ID or a snowflake
ID can come out of JSON.parse a few digits different from what was sent. The fix is on the
producing side: serialise large identifiers as strings.
Duplicate keys are legal but lossy
{"a":1,"a":2} parses without complaint and the last value wins, so this formatter will show
you a single a. If a document loses fields after formatting, duplicate keys upstream are the
likely cause.
Key order is not guaranteed
The specification treats an object as unordered. Most implementations preserve insertion order in practice, but you should never depend on it — use the sort option here when you need two documents to be comparable.
Encoding and escaping
JSON text is UTF-8. Control characters, double quotes and backslashes must be escaped inside strings, and
a raw newline inside a string is invalid — it has to be written \n. When a payload has been
through a shell or a log pipeline, everything is often double-escaped, so \\n appears where a
real newline belongs. If a value looks like Base64 rather than text, run it through the
Base64 decoder; if it is full of %20 sequences, it needs the
URL decoder instead.
Frequently asked questions
Why does my JSON fail when it looks fine?
Check for a trailing comma, single quotes, unquoted keys or a comment. All four are valid JavaScript and none are valid JSON. The error message here gives the line and column so you can go straight to it.
Is anything I paste sent to a server?
No. Parsing and formatting run in this page. There is no upload, no logging and no storage, so pasting a production API response is safe.
What is the difference between format and minify?
They produce identical data. Formatting adds whitespace for humans; minifying removes all of it to shrink the payload. Use formatted output to read, minified output to send.
Can I put comments in JSON?
Not in real JSON. JSON5 and JSONC support comments, but an API expecting application/json
will reject them. If you need a note, add a field such as "_comment".
Does the formatter change my data?
Only in ways that preserve meaning: whitespace changes, and if you sort keys, object member order. Numbers are re-serialised from their parsed value, so an extremely large integer may be rewritten — that reflects a real precision loss in JSON, not a bug in the tool.
Related tools and reference
API Tester
Send a request and get the JSON response back formatted automatically.
JWT Decoder
Decode a token and inspect the JSON payload hiding inside it.
Base64 Encoder & Decoder
Turn a Base64 field inside a payload back into readable text.
HTTP Status Codes
Work out why a response contained an HTML error page instead of JSON.