JSON Formatter & Validator
A JSON formatter with a validator attached: indent at 2 or 4 spaces, minify to one line, or fold a huge payload into a tree.
How to use
- Drop the payload into JSON to format, set Indent to 2 spaces or 4, then press Format. Minify is the other direction, and Sort keys applies to both of them.
- Take the result with the copy button above the output, or flip that panel to Tree first if you would rather fold your way down than scroll.
About this tool
Paste something unreadable into the top box, press Format, and it comes back indented at 2 spaces or 4, whichever you picked. Minify goes the other way and squeezes the whole thing onto one line. That is the entire job of a JSON formatter for most visits, and the rest of this page exists for the payloads that will not cooperate. Worth saying once, because it is the reason I stopped pasting into other people's formatters: the text is parsed by the page and goes nowhere else, which matters when the response you are debugging still has a live bearer token sitting in it.
When a payload refuses to parse, the message underneath comes from the browser's own parser and names the exact character. Expected double-quoted property name in JSON at position 7 is almost always a trailing comma. A Repair button also appears next to Minify at that moment, and only at that moment. It runs the text through jsonrepair, which knows the usual damage: single quotes, unquoted keys, Python's True and None, an object that got truncated halfway. The status line afterwards tells you to check the result. Do check it, because repair is a guess about what you meant.
Sort keys alphabetises every object at every depth, and it applies to Minify as well as Format. It is the quickest way to make two config files comparable before you diff them. Array order is left exactly as it was, because in an array the order is data.
The extract field takes a plain path like items[0].name and shows that value on its own, re-indented. It reads whatever is in the input box, which means a 4,000-line response will give up one field without being formatted at all. Get the path wrong and it says so in words rather than a stack trace: "name" needs an object.
Tree turns the output into a folding outline. Every object and array becomes a row labelled with its size, so a big response reads as Object(7) and Array(1204) until you open the branch you want. Six levels start open and everything deeper stays shut. Lists render 200 children at a time behind a Show N more button, which is what stops a ten-thousand-element array from locking up the tab.
Good to know
- Indent is 2 spaces or 4. There is no tab option and no third width, and Minify ignores the setting entirely.
- The extract path understands dots and [0] and nothing more. A key with a space in it is fine, items[0].full name resolves, but a key with a dot inside its own name has no way through.
Things people ask
Does formatting change my data?
Only the whitespace, with one exception worth knowing about. Numbers go through the browser's parser, so 1.0 comes back as 1, 1e2 comes back as 100, and an integer longer than about 15 digits loses precision: paste 12345678901234567890 as an id and it formats to 12345678901234567000. Keys keep their original order unless Sort keys is ticked.
My JSON is rejected and I cannot see why. What now?
Read the position number in the message first, because it points at the exact character that broke. The usual culprits are a trailing comma after the last item, a single quote where a double belongs, or a bare unquoted key. Press Repair if you would rather skip the hunt; it turns up beside Minify the moment a parse fails.
How do I pull one field out of a huge response?
Type the path into the extract field: items[0].name, data.user.email, whatever the shape happens to be. The value appears on its own in the output at your chosen indent. It runs against the input box, so a raw unformatted payload works fine, and the result updates while you type.
A 5,000-line response is too big to read. Where do I start?
Switch the output to Tree. Everything collapses into rows labelled with a count, Object(7) or Array(1204), and you open only the branch you care about. Six levels are open when it draws. Arrays keep anything past the first 200 items behind a Show N more button. The tree reads the input box directly, so an unparseable payload asks you to fix it before it will draw anything.
My object has the same key twice. Which one survives?
The last one, silently. Parsing goes through the same JSON.parse the browser uses everywhere else, and it assigns each key as it reads, so {"id": 1, "id": 2} formats down to a single id of 2 with the first value gone and no warning anywhere. Search the raw text for the key before you format if you are chasing a bug in something a service generated.
Repair rewrote my input box. Can I get the original text back?
Not from this page. Repair writes its output straight into the top box, over the text that was there, and nothing keeps a copy of what you pasted. Paste it again from wherever it came from if the result looks wrong. Read that result properly either way, because jsonrepair is guessing at intent when it swaps a quote or closes an object that got cut off mid-stream.
Can I sort the keys to line two config files up?
That is what Sort keys is for. Tick it, format both files, and the two outputs sit in the same order so an eyeball comparison shows only the real differences. Every object gets sorted, at every level. If you would rather have the comparison done for you, the JSON diff tool ignores key order without any sorting at all.
Missing something in JSON Formatter & Validator? Suggest a feature →
Tell someone who needs this.