How to format JSON
- Paste your JSON into the JSON input box, or press Upload .json to open a file. Press Sample to try it with example data.
- It is formatted as you type or paste. Choose 2 spaces, 4 spaces or Tab under Indent, and tick Sort keys to put every object's keys in alphabetical order.
- Press Minify to remove all whitespace instead, or Format to go back to pretty printed JSON.
- Press Copy or Download to take the result with you. Ctrl+Enter (Cmd+Enter on a Mac) re-runs the last action.
JSON pretty print example
A compact API response is hard to read on one line:
{"id":7,"tags":["a","b"],"owner":{"name":"Ada"}}Formatted with 2 spaces, each key and array item gets its own line and nesting is indented:
{
"id": 7,
"tags": [
"a",
"b"
],
"owner": {
"name": "Ada"
}
}With Sort keys ticked, {"name":"Ada","id":7,"active":true} becomes:
{
"active": true,
"id": 7,
"name": "Ada"
}Sorting uses character order, like jq -S: uppercase letters before lowercase, and "10" before "2". Sorted JSON is easier to scan and to compare between versions.
JSON minify: make it as small as possible
Minifying removes every space, tab and line break that sits outside a string. The pretty printed example above shrinks from 83 to 48 characters:
{"id":7,"tags":["a","b"],"owner":{"name":"Ada"}}Use minified JSON for API payloads, environment variables, fixtures and anywhere size matters. Use formatted JSON for code review, docs and debugging. Both hold exactly the same data.
How to validate JSON
Every time you type, paste or press Validate, the input is parsed with your browser's own JSON parser, the same strict one your JavaScript code uses. If it is valid you see what it contains, for example "an object with 12 keys". If not, you get:
- the line and column of the first error, even in browsers whose own error message has no position;
- a plain-English explanation of what is wrong and how to fix it;
- a snippet of the lines around the error with the problem character highlighted, and a Show in input button that jumps to it.
For example, this object has a comma after its last property:
{
"name": "Ada",
"langs": ["en", "fr"],
}The validator reports Invalid JSON at line 4, column 1: Trailing comma: JSON does not allow a comma after the last property. Remove the comma at line 3, column 24. Remove that comma and it passes.
It also warns about things that are technically valid but risky: duplicate keys (most parsers silently keep only the last value), numbers too large for JavaScript, and a byte order mark (BOM) at the start of a file saved by some Windows editors, which it removes for you.
Why is my JSON invalid? Common errors and fixes
These are the messages the validator gives for the mistakes we see most often:
- Trailing comma:
["en", "fr",]
line 1, col 13: Trailing comma: JSON does not allow a comma after the last item. Remove the comma at line 1, column 12. - Single quotes:
{'name': 'Ada'}
line 1, col 2: Property names need double quotes ("name"), not single quotes. - Unquoted key:
{name: "Ada"}
line 1, col 2: Property names must be in double quotes, like "name": 1. - Missing comma:
{"name": "Ada" "age": 36}
line 1, col 16: Missing comma: add a comma between the previous property and this one. - Comment:
{"a": 1 // note↵}
line 1, col 9: JSON does not allow comments (// or /* */). Remove the comment. - NaN or undefined:
{"score": NaN}
line 1, col 11: NaN is not a JSON value. Use null, a number or a string instead. - Python True/None:
{"active": True}
line 1, col 12: True is Python, not JSON. Write true (lowercase) instead. - Leading zero:
{"zip": 02134}
line 1, col 10: Numbers cannot have leading zeros: write 7, not 07 (or use a string for codes like "007"). - Unescaped backslash:
{"path": "C:\Users"}
line 1, col 14: Invalid escape "\U" in a string. JSON allows only \" \\ \/ \b \f \n \r \t and \uXXXX. For a literal backslash, write \\. - Missing bracket:
{"langs": ["en", "fr"]
line 1, col 23: The JSON ends too early: the { at line 1, column 1 is never closed. Add the missing }.
JSON is stricter than JavaScript: keys and strings always use double quotes, there are no comments, no trailing commas, and the only literals are true, false and null, all lowercase.
JSON formatter vs JSON validator vs JSON lint
- JSON validator: answers "is this valid JSON?" and points to the error. Same as JSON lint, named after the JSONLint tool.
- JSON formatter, JSON beautifier or pretty printer: rewrites valid JSON with indentation so it is readable. It validates first, because it cannot format broken JSON.
- JSON minifier: the reverse of a beautifier. Same data, no whitespace.
- JSON viewer: shows the data as a tree you can fold and search. Use the JSON viewer when a formatted file is still too long to read.
Big numbers, duplicate keys and key order
Many online formatters run JSON.parse and then JSON.stringify, which quietly changes your data: numbers above 253 are rounded, duplicate keys collapse to the last one, and keys that look like integers ("2", "10") jump to the front of each object. This formatter re-indents the original text instead, so when you format or minify, every number, escape sequence, key and key order stays exactly as you wrote it. Only Sort keys rebuilds the JSON from parsed values, and the tool tells you if that rounds a number.
More JSON tools
- JSON viewer: explore JSON as a collapsible tree and copy the path to any value.
- JSON compare: find what was added, removed or changed between two JSON documents.
- JSON to CSV converter: turn an array of objects into a spreadsheet.
- JSON to YAML converter for config files.
- JWT decoder: read the JSON inside a JSON Web Token, and Base64 decode for encoded payloads.
Frequently asked questions
Is my JSON sent to a server?
No. The formatter and validator run entirely in your browser with JavaScript. Nothing you paste or upload is sent to our servers, logged or saved, so it is safe to format API responses or config files that contain tokens. Only your settings (indent size, sort keys, format as I type) are remembered on your device. Once the page has loaded it keeps working without an internet connection.
Why is my JSON invalid?
The most common causes are a trailing comma after the last item, single quotes instead of double quotes, property names without quotes, a missing comma between two items, comments, and values JSON does not have such as NaN, undefined or Python's True and None. The validator shows the line and column of the first error, highlights it, and explains how to fix it. Fix that one and check again, because one mistake can hide the next.
What is the difference between a JSON formatter and a JSON validator?
A JSON validator checks whether text is valid JSON and tells you where it breaks. A JSON formatter (or beautifier, or pretty printer) rewrites valid JSON with consistent indentation and line breaks so people can read it. A formatter has to parse the JSON first, so every format is also a validation. This tool does both: invalid JSON gets an error with its location, valid JSON gets formatted.
How do I pretty print JSON?
Paste it into the box above and it is pretty printed with 2 spaces as you type. Choose 4 spaces or a tab under Indent. In code, JSON.stringify(value, null, 2) does the same in JavaScript, python -m json.tool file.json in Python, and jq . file.json on the command line.
Does minifying JSON change the data?
No. Minifying only removes spaces, tabs and line breaks outside strings. Spaces inside strings are kept, and so are the keys, their order and every value. A minified file is smaller and faster to send, and it parses to exactly the same data as the formatted one.
Why does my large number change, like 12345678901234567890 becoming 12345678901234567000?
JavaScript stores numbers as 64-bit floating point, which is exact only up to 2^53 − 1 (9,007,199,254,740,991). Bigger integers, such as 64-bit database IDs, are rounded by JSON.parse in browsers and Node.js. This formatter keeps numbers exactly as you typed them when it formats or minifies, and warns you when a number would lose precision. Sort keys has to parse the values, so it rounds them. The safe fix is to send large IDs as strings.
Does JSON allow comments or trailing commas?
No. Standard JSON (RFC 8259) allows neither. Formats such as JSONC (used in VS Code settings) and JSON5 accept them, but JSON.parse, most APIs and this validator reject them. Remove comments and the comma after the last item in each object or array.
Can it format large JSON files?
Yes. Files of several megabytes format in well under a second on a typical laptop, and the page stays responsive while you type because large inputs are checked after a short pause. Use Upload to open a .json file instead of pasting it, and Download to save the result. For exploring a big file, the JSON viewer shows it as a collapsible tree.
Do I need a JSON formatter extension or download?
Not for occasional use: this page works in any modern browser, on desktop or phone, with nothing to install. Browser extensions help if you want every JSON URL you open to be formatted automatically. In VS Code, open a .json file and press Shift+Alt+F (Windows, Linux) or Shift+Option+F (Mac) to format it.