JSON Formatter and Validator
Indent, minify and check JSON as you type. When it will not parse, this page names the line and column where the text stops making sense.
Nothing you paste is uploaded. The text is read and rewritten in this page, and the check runs on every keystroke.
{
"Image": {
"Width": 800,
"Height": 600,
"Title": "View from 15th Floor",
"Thumbnail": {
"Url": "http://www.example.com/image/481989943",
"Height": 125,
"Width": 100
},
"Animated": false,
"IDs": [
116,
943,
234,
38793
]
}
}307 characters in, 302 out — 2% smaller.
What is left untouched
- The order of your keys, including keys that look like numbers.
- Every digit of every number, so a trailing zero or a very long integer survives.
- The escapes inside a string, exactly as you wrote them.
Every JSON tool will tell you a document is invalid. Very few will tell you where. This one reads the text with its own scanner rather than handing it to the browser, so when something is wrong you get a line and a column and a sentence about what the grammar expected there — not the word "unexpected" and a character offset you then have to count to. When the document is valid it is re-indented, or squeezed onto one line, with the order of your keys and the exact digits of your numbers left alone. Nothing you paste is uploaded; the whole thing runs in this page.
How it is calculated
JSON-text = ws value ws — whitespace between tokens carries no meaning
Formatting JSON is legal precisely because the grammar treats the space between the six structural characters as insignificant. Indenting adds that space back at one level per depth of nesting; minifying removes all of it. Nothing inside a string or a number is touched by either, which is why the spaces in a sentence survive and a trailing zero on a decimal survives with them.
Questions people ask
- Does formatting change the order of my keys?
- No. The properties come out in the order you wrote them, including keys that look like numbers, which a round trip through a JavaScript object would silently reorder. Be aware, though, that the specification says an object is an unordered collection of name/value pairs, and that parsing libraries have been observed to differ over whether they expose member order at all. Every implementation you are likely to meet keeps insertion order, but nothing entitles you to rely on it.
- Will my numbers survive exactly as I wrote them?
- Yes. A number is carried through as the text you typed rather than converted to a floating point value and printed back, so -122.026020 keeps its trailing zero, 1E400 stays 1E400, and an integer too large for a double is not rounded on the way past. That is a deliberate difference from tools built on parse-then-stringify, which quietly rewrite all three.
- Why does it reject a trailing comma when my editor accepts it?
- Because JSON has no trailing comma and never has. The grammar puts a comma between two members and nowhere else. JSON5, JSONC and the tsconfig dialect all allow one, which is why the habit spreads, but a strict parser at the other end of a request will refuse the document.
- What counts as a column?
- Characters, counted from one, starting again at every line break. A tab counts as a single column rather than jumping to the next tab stop, so a position may sit slightly left of where your editor draws it in a tab-indented file. Both a lone carriage return and a carriage return with a line feed start a new line.
- What happens to a property that appears twice?
- Both copies are kept and shown back to you, and the page says which name was repeated. The specification says names within an object should be unique and warns that behaviour is unpredictable when they are not — some implementations keep the last, some fail, some keep everything. Silently dropping one of them here would hide the very thing worth seeing.
- Is there a limit on what it will read?
- Nesting stops at two hundred levels. The specification explicitly allows an implementation to set limits on depth, and the alternative to a stated limit is a page that runs out of stack and dies without saying why. Length is limited only by your machine.
Related tools
SHA Hash Generator
Hash text with SHA-1, SHA-256, SHA-384 and SHA-512 as you type. Your browser does the work, so the text never leaves the page.
Base64 Encode and Decode
Turn text into Base64 and back as you type, in the standard alphabet or the URL-safe one. Nothing you paste leaves the page.
URL Encoder and Decoder
Percent-encode text as you type, choosing whether you are escaping one value inside a URL or an address as a whole. Nothing is uploaded.
Found a problem, or want more?
A number that disagrees with its source is a defect, not a rounding preference.
What did you enter, what did the tool show, and what did you expect instead? If you have a source that disagrees with ours, a link to it is the most useful thing you can send.
Opens your mail app with the page and tool already filled in.