JSON Formatter
Format, minify, and validate JSON. Choose an indent level to pretty-print for readability, or compress to a single line. Syntax errors are highlighted instantly.
What a JSON formatter does
A JSON formatter takes JSON crammed onto a single line and lays it out again with indentation, or does the reverse — strips the whitespace and packs it back onto one line. Since it parses the input to do either, it also tells you at once whether the syntax is sound, so pasting an API response or a configuration file gets you formatting, minifying and validation together. Indentation can be two spaces, four spaces or a tab.
The judgement is made by the browser’s own JSON parser, so you will not meet the mismatch where something passes here but fails in your runtime. Everything happens inside your device: the JSON you paste is never sent to a server. Even an API response carrying an authentication token or personal data can be tidied up without any of it leaving the machine.
How to use the JSON formatter
- Paste your JSON Paste it into the input box on the left. If you have nothing to hand, the sample button loads an example.
- Choose the indentation Pick two spaces, four spaces or a tab. Matching your project’s formatting rules means you can paste the result straight back.
- Check the valid / invalid badge The badge switches as you type. When the JSON is invalid, the parser’s own error message is shown as it stands, so you can trace which line and character it stopped at.
- Copy either the formatted or the minified result “Copy formatted” puts the indented result on the clipboard; “copy minified” puts the single line with the whitespace removed.
- Read the line and byte counts The line count is of the formatted result; the byte count is of the minified result, measured in UTF-8. Use the latter when estimating how much you will be transferring.
Tips for getting more out of it
- JSON keys must always be wrapped in double quotes. Single quotes are not valid.
- Trailing commas (
{"a":1,}) are invalid per the JSON specification. - Numbers in e-notation are valid. However,
NaNandInfinityare not. - Double quotes inside strings must be escaped as
\". Use\nfor newlines and\tfor tabs. - Minification is useful for reducing file size. Use the minified version for API transfers and the formatted version for config files.
Where a JSON formatter helps
Reading through an API response
Format a response that came back on one line and the depth of the nesting and the number of elements in each array become something you can follow by eye. This is far and away the commonest use, both while building and while chasing a bug.
Pinning down a syntax error in a configuration file
When an application refuses to load its configuration, pasting the file in and validating it identifies the cause on the spot — a trailing comma, a quote left unclosed.
Minifying to cut down what you transfer
Returning formatted JSON as an API response or embedded data wastes bandwidth on the indentation alone. Use the minified version for anything you ship.
Tidying code samples for documentation or an issue
Put the request and response examples that go into a specification or a bug report into a readable, evenly indented shape.
Preparing input before converting it
Confirming the syntax first spares you obscure errors on the far side when you hand the data to JSON to TypeScript types or JSON to XML.
Terms used with JSON
- JSON
- Short for JavaScript Object Notation, the data interchange format laid down in RFC 8259. It is built from just six things — object, array, string, number, boolean and null — and because any language can read and write it, it has become the standard format for web APIs.
- Pretty-printing
- Rebuilding the text with indentation and line breaks that follow the depth of the nesting, so a person can read it. The data itself is unchanged; only its appearance is.
- Minifying
- Removing every space and line break that carries no meaning and packing the result onto one line. The byte count falls, so less is transferred, but it is no longer meant for human eyes.
- Validation
- Checking that the input follows the grammar of JSON. This tool has the browser’s parser do the work and shows you its error message verbatim when it fails.
- Escape sequence
- A way of writing, with a backslash, characters that cannot stand as they are inside a string. A double quote is
\", a newline\n, a tab\t. - Key order
- JSON itself lays down no order for the keys of an object. Because this tool passes the data through a JavaScript object, only keys that read as integers —
"1","2"and the like — are reordered into ascending sequence. Every other key keeps the position in which it was written. - UTF-8
- The character encoding RFC 8259 requires JSON to use. Characters outside ASCII occupy several bytes each, so a count of characters and a count of bytes will not agree.
Frequently Asked Questions
undefined, functions, NaN, and Infinity cannot be used.number type. Large integers may lose precision in JavaScript if they exceed MAX_SAFE_INTEGER.
Side Note — Why JSON Won Over XML
In the early 2000s, XML was the dominant data format. In 2001, Douglas Crockford proposed JSON as a lighter, more approachable, and more readable alternative. By the 2010s, JSON had become the standard.
For the same data, JSON is often 30–50% smaller in byte count than XML — a difference that directly translated to faster app response times in the era of mobile data connections.
RFC 8259 states that duplicate keys are "SHOULD NOT" — not prohibited. {"a":1,"a":2} is syntactically valid, but its behavior is undefined.