JSON Formatter & Validator
Pretty-print or minify JSON in the browser.
What this JSON formatter does
This JSON formatter turns hard-to-read JSON into neatly indented text, or compresses it onto a single line. Because it fully parses your input first, it also works as a quick JSON validator: if the JSON is broken, you get an "Invalid JSON" message instead of a result. Everything happens in your browser, so the data you paste stays on your device.
It is useful for developers debugging API responses, QA testers checking payloads, data analysts looking at exports, and anyone who has opened a configuration file and seen one enormous line of brackets and quotes.
How to use the JSON formatter
- Paste your JSON into the JSON box.
- Click Pretty print to format it with a two-space indent, one key per line.
- Or click Minify to remove all unnecessary whitespace and get a compact single line.
- Use the Copy button below the result to copy the output.
If you see "Invalid JSON", the text could not be parsed. Fix the error (see the common mistakes below) and try again.
Examples
Pretty print
Input: {"user":{"id":42,"name":"Ana","roles":["admin","editor"]},"active":true}
Output: the same data with each key on its own line, nested objects and arrays indented by two spaces, so you can follow the structure and spot the value you need.
Minify
Minify does the opposite: it removes the line breaks and indentation, producing the shortest valid text for the same data. This is handy for embedding JSON in a request body, an environment variable or a test fixture.
Formatting never changes the data itself. Keys, values and their order stay the same; only the whitespace between them changes.
What counts as valid JSON
JSON (JavaScript Object Notation) is defined by RFC 8259 and ECMA-404. The rules are strict:
- Keys must be strings in double quotes.
- Strings use double quotes, not single quotes.
- Allowed values are strings, numbers, objects, arrays, true, false and null.
- No trailing comma after the last item in an object or array.
- No comments.
- Special characters in strings, such as line breaks, must be escaped (for example \n).
Common use cases
- Reading an API response copied from browser developer tools, curl or a log file.
- Checking that a configuration file (such as package.json or a settings file) is valid before committing it.
- Minifying JSON to paste into a single-line field or a command.
- Comparing two payloads: pretty-print both, then compare them line by line.
- Teaching or learning the structure of nested objects and arrays.
Tips and common mistakes
- Trailing commas such as [1, 2, 3,] are allowed in JavaScript code but not in JSON. Remove the last comma.
- Single quotes like {'a': 1} are not valid JSON. Use {"a": 1}.
- Unquoted keys like {a: 1} are JavaScript object syntax, not JSON.
- Comments (// or /* */) are not part of JSON. Some tools accept "JSON with comments", but a standard parser rejects them.
- Copied text with extra content. Log lines often include a timestamp or prefix before the JSON. Paste only the part that starts with { or [.
- Very large numbers. JavaScript stores numbers as 64-bit floating point, so integers larger than 2^53 − 1 (9,007,199,254,740,991) can lose precision when parsed in a browser. If you work with large IDs, keep them as strings.
- Sensitive data. Parsing is done locally, but it is still good practice to remove passwords, tokens and personal data before pasting payloads anywhere.
Frequently asked questions
Does this tool validate JSON?
Yes, in a basic way. The text must parse as valid JSON before it can be formatted, so an "Invalid JSON" message tells you there is a syntax error. It does not check your data against a JSON Schema.
Is my JSON sent to a server?
No. Parsing and formatting run in your browser.
What is the difference between pretty print and minify?
Pretty print adds line breaks and indentation for humans. Minify removes them to make the text as short as possible for machines. The data is identical in both.
Why does my JSON fail even though it looks right?
The usual causes are a trailing comma, single quotes, an unquoted key, a comment, or "smart quotes" that a word processor inserted instead of straight double quotes.
Does pretty print change the order of keys?
No. Keys stay in the order they were parsed. Only whitespace changes.
Can I format JSON Lines (one JSON object per line)?
Not as a whole file, because JSON Lines is several JSON documents rather than one. Paste one line at a time, or wrap the objects in an array.
Related tools
- XML Formatter – pretty-print, minify or validate XML.
- JWT Decoder – read the JSON header and payload inside a token.
- Base64 Encode / Decode – decode Base64 strings that contain JSON.
- HTML Formatter – indent or minify HTML markup.
- Regex Tester – test patterns for extracting values from text.