How to format JSON online
- Paste or open your JSON. Paste text into the input box, click Open file, or drag a
.jsonfile onto the box. Pasting formats automatically. - Pick an indent. Two spaces is the most common style (it is what
JSON.stringify(data, null, 2)and Prettier produce); four spaces matches Python'sjson.dumps(indent=4); tabs keep files small and let each reader choose a width. - Click Format / Beautify (or press Ctrl/⌘ + Enter). Valid JSON is pretty-printed with syntax colours. Invalid JSON is not guessed at: you get the line, the column, the offending text and a hint.
- Copy or download the result, or click Minify to get the same data back on a single line.
If the input is not strict JSON — a JavaScript object literal, a config file with comments, a Python dict printed to a log — use Clean & repair instead. It converts the input to valid JSON and lists every change it made.
JSON beautifier and prettier: pretty print options
Beautifying (also called pretty printing) only changes whitespace: each object member and array item goes on its own line, indented by its depth. The data — keys, values and their order — stays the same. Here is the same document minified and beautified with two-space indentation:
{"id":7,"tags":["new","sale"],"price":{"amount":19.99,"currency":"EUR"}}
{
"id": 7,
"tags": [
"new",
"sale"
],
"price": {
"amount": 19.99,
"currency": "EUR"
}
}
JSON sorter: sort keys alphabetically
The Keys menu turns the formatter into a JSON sorter. Sort A–Z (all levels) sorts the members of every object at every depth, like jq -S. Top level only sorts the outer object and leaves nested objects in their original order. Ignore case puts apple, Banana and cherry in dictionary order instead of ASCII order, where every uppercase letter sorts before every lowercase one. Arrays are never reordered, because array order is part of the data.
| Keys | A–Z (ASCII) | A–Z, ignore case |
|---|---|---|
b, B, a, _id, 10, 9 | 10, 9, B, _id, a, b | 10, 9, _id, a, b, B |
Sorted keys make config files diff cleanly in Git and line up objects that came from different serializers. To compare two documents directly, use the JSON diff checker, which ignores key order for you. Drop duplicate keys keeps only the last value of a repeated key, which is what JSON.parse and Python's json.loads do anyway. This way you can see exactly what your program will receive.
JSON syntax highlighting for docs and chat
The output is colour-coded by type: keys, strings, numbers, booleans and null. To paste highlighted JSON somewhere else, choose a format next to Copy. Markdown code block wraps the result in a ```json fence, which GitHub, GitLab, Slack, Notion and most static-site generators colour automatically. Coloured HTML copies a self-contained <pre> with inline styles that keeps its colours in a blog post, an email or a CMS that strips stylesheets.
This formatter also keeps numbers exactly as you wrote them. Most online formatters run your input through JavaScript's JSON.parse, which turns 12345678901234567890 into 12345678901234567000 and 1.50 into 1.5. That is a silent data change, and a real problem for 64-bit database IDs and tweet IDs. NeatJSON parses JSON with its own parser and prints each number from the original text. If you paste an integer that JavaScript cannot hold exactly, a note under the tool tells you which one.
JSON cleaner: clean up and tidy messy JSON
A lot of text that looks like JSON is not strict JSON. It might be a JavaScript object pasted from source code, a tsconfig.json or VS Code settings file with comments, a Python print(dict) from a log, output from an LLM, or a response cut off halfway through. Clean & repair turns all of these into valid, tidy JSON. Here is what it fixes:
| Problem | Messy input | Cleaned output |
|---|---|---|
Comments (//, /* */, #) | {"port": 80 // http} | {"port": 80} |
| Trailing commas | [1, 2, 3,] | [1, 2, 3] |
| Single-quoted strings | {'name': 'Ada'} | {"name": "Ada"} |
| Unquoted keys | {name: "Ada"} | {"name": "Ada"} |
| Curly “smart” quotes | {“a”: 1} | {"a": 1} |
| Python literals | {"ok": True, "x": None} | {"ok": true, "x": null} |
| JavaScript-only values | {"a": undefined, "b": NaN} | {"a": null, "b": null} |
| Missing commas between items | {"a": 1 "b": 2} | {"a": 1, "b": 2} |
| Non-standard numbers | [.5, +1, 007, 0x1F] | [0.5, 1, 7, 31] |
| Truncated input | {"items": [1, 2 | {"items": [1, 2]} |
| Several documents (NDJSON) | {"a":1} newline {"a":2} | [{"a": 1}, {"a": 2}] |
| BOM and non-breaking spaces | invisible characters | removed |
Repairs are not silent. After cleaning you get a list of each kind of fix and how many times it was applied. Check that list: a truncated array has been closed, but the records that were cut off are still missing. Duplicate keys are kept and flagged, because most parsers would quietly keep only the last value.
JSON validator and fixer: common errors and how to fix them
The validator follows RFC 8259, the JSON standard, and stops at the first problem. Browsers report errors differently (“Unexpected token } in JSON at position 212” in Chrome, “JSON.parse: expected double-quoted property name” in Firefox), so NeatJSON gives its own message with the line, the column and the likely cause. These are the messages you will see most:
| Message | Usual cause | Fix |
|---|---|---|
| Trailing comma before } / ] | A comma after the last member, which JavaScript allows and JSON does not | Delete the final comma |
| Expected “,” or “}” after a property value | A comma is missing between two members, often after a copy-paste edit | Add a comma at the end of the line before |
| Object keys must be double-quoted strings | JavaScript object-literal syntax: {id: 1} | Quote the key: {"id": 1} |
| Strings must use double quotes | Single quotes, from JavaScript or Python | Replace ' with " |
| Unexpected end of input: missing } | Truncated response or an unclosed bracket | Close the bracket, or fetch the full response |
| Unescaped control character inside a string | A literal line break or tab inside quotes | Write it as \n or \t |
| Numbers cannot have leading zeros | ZIP codes, phone numbers or IDs written as 007 | Make it a string: "007" |
| Comments are not allowed in JSON | A JSONC / JSON5 config file | Remove comments, or use Clean & repair |
| Byte-order mark (BOM) at the start | File saved as “UTF-8 with BOM”, often by Windows tools | Save as UTF-8 without BOM |
Why not just auto-fix everything? Some errors are ambiguous. A missing quote can end a string in more than one place, and a closed truncated array still lacks the cut-off records. So Validate and Format report the problem and leave your text alone, and Clean & repair fixes only the patterns it can fix safely and lists every change. For checks beyond syntax, such as required fields, types and allowed values, you need a schema. The JSON validator page covers that.
JSON parser online: what strict parsing accepts
Validate works like a strict RFC 8259 JSON parser, and it is useful for checking what an API or a JSON.parse call will accept before you ship it.
- Any value can be the top level.
"hello",42andnullare complete JSON documents, not just objects and arrays. - One value per document. JSON Lines / NDJSON (one object per line) is not a single JSON document. Clean & repair wraps the lines in an array so you can format and inspect them.
- Numbers are exact text. The grammar allows integers of any size, but
JSON.parseturns them into 64-bit floats. So{"n": 12345678901234567890}comes back as12345678901234567000in JavaScript. Here it is kept as written. - Duplicate keys parse. The spec says names “SHOULD be unique” but does not forbid repeats. They parse, and this tool warns you about them.
- Only four whitespace characters count. These are space, tab, line feed and carriage return. A non-breaking space copied from a web page is a syntax error.
Simplify JSON: minify vs. beautify
Minifying removes every space and line break that is not inside a string. The data does not change and any JSON parser reads both versions the same way. Minified JSON is usually 15–30% smaller than two-space pretty JSON, and more when nesting is deep. Most of that difference disappears once the response is gzip- or brotli-compressed, so minify for storage, logs, query strings and payload limits (message queues, environment variables, localStorage). Beautify anything a person needs to read or review. The JSON minifier also reports byte savings, if that is all you need.
Pretty print JSON in code and on the command line
JavaScript / Node.js
const pretty = JSON.stringify(JSON.parse(text), null, 2); // 2-space indent
const min = JSON.stringify(JSON.parse(text)); // minified
Python
import json
data = json.loads(text)
print(json.dumps(data, indent=2, ensure_ascii=False, sort_keys=True))
# from a shell: validate and pretty print a file
python3 -m json.tool data.json
jq (command line)
jq . data.json # pretty print (also validates)
jq -c . data.json # minify to one line
jq -S . data.json # sort keys
curl -s https://api.example.com/users | jq .
Java (Jackson)
ObjectMapper mapper = new ObjectMapper();
Object tree = mapper.readTree(text);
String pretty = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(tree);
These tools do not all behave the same way. Python's json.tool accepts NaN and Infinity, which strict JSON does not, and JavaScript rounds large integers. jq keeps number literals exactly in version 1.7 and later.
More JSON tools
Frequently asked questions
What is a JSON formatter?
A JSON formatter (or JSON beautifier) takes compact or badly indented JSON and rewrites it with consistent indentation and one member per line so a person can read it. It changes only whitespace, never the data. NeatJSON also validates the input while formatting and reports the exact line and column of any error.
How do I clean up messy JSON?
Paste it into the input box and click Clean & repair. The JSON cleaner strips comments, removes trailing commas, converts single quotes and smart quotes to double quotes, quotes bare keys, replaces Python True/False/None, closes truncated brackets, and then prints tidy, valid JSON with a list of every fix it applied.
Why does my JSON say it is invalid?
The most common causes are a trailing comma after the last item, a missing comma between two items, single quotes instead of double quotes, unquoted keys, and comments. The validator shows the line and column where parsing stopped. The real mistake is usually at that spot or just before it.
Is it safe to paste confidential JSON here?
Yes. Formatting, validation and repair all run in JavaScript in your browser tab. Your JSON is not sent to a server, logged or stored, and the tool keeps working if you go offline after the page loads.
What is the difference between formatting and validating JSON?
Validating checks that the text follows the JSON grammar: double-quoted keys, no trailing commas, correct nesting and so on. Formatting changes how valid JSON is laid out. You cannot reliably format invalid JSON, so this tool validates first, then formats. Clean & repair is the step in between for input that is almost JSON.
Does formatting change my numbers or key order?
No. Keys stay in their original order unless you turn on Sort keys, and numbers are printed exactly as written, so large integers such as 64-bit IDs are not rounded the way JSON.parse would round them.
How do I pretty print JSON from the command line?
Use jq . file.json to pretty print (and validate) a file, jq -c . to minify it, or python3 -m json.tool file.json if Python is installed. In Node.js, JSON.stringify(JSON.parse(text), null, 2) gives two-space indentation.