JSON Formatter: Format, Validate and Minify, With an Error That Tells You Where
Most of the time you reach for a JSON formatter because something is wrong. An API response arrived as one unreadable line, a config file refuses to load, or your program printed “Unexpected token in JSON at position 847” and you have no idea which line that is. This tool is a JSON validator and JSON beautifier in one pane, and its error message names what the parser expected at a line and column rather than a character offset. This guide covers each message, the mistake behind it, and the minify, indent and sort options once the data is valid.

1. What a JSON Formatter Checks: Valid JSON Means Strict JSON
JSON looks forgiving because it looks like code. The format itself is not. It is defined by IETF RFC 8259 and ECMA-404, and the grammar is small: objects, arrays, double-quoted strings, numbers, true, false and null. Nothing else.
That small grammar is why so much pasted text fails. The things a Python dictionary or a code-style object literal allow — single quotes, unquoted keys, a comma after the last item, a comment, a NaN — are all invalid JSON. This JSON validator checks strictly against the standard and reports the first thing it cannot accept. It does not quietly allow JSON5 or comments, and it does not repair what it finds; it tells you where the standard was broken so you can fix the source.
2. How to Format JSON Online Free (Step-by-Step)
No account, no email, nothing gated behind a plan. If you searched for how to format JSON, this is the whole process with the free online JSON formatter above:
Paste your JSON
Replace the sample in the left-hand box with your own text. Validation runs as you type.
Read the banner
Green means valid, with a count of keys, the nesting depth and the size in bytes. Red means invalid, with a named reason and a line and column.
Format, copy or download
The right-hand pane shows the pretty-printed result. Click Format to rewrite your input at the chosen indent, Copy for the clipboard, or Download to save formatted.json.
The input is a text box, so this is a paste-and-read tool rather than a file picker. Open the .json file in any editor, select all, copy and paste; if the export arrived zipped, run it through extract archive first. That is also the answer to JSON pretty print online: console output copied out of a log formats the same way as a saved file.
3. Why Is My JSON Invalid? A JSON Formatter With Line and Column Error Reporting
The error most programs print when JSON fails to parse is some form of “Unexpected token in JSON at position 847”. Position 847 is a character offset from the start of the text. Nobody counts 847 characters by hand, and a minified response has no line breaks to help. Most tools you paste it into either repeat the offset or show a bare “Invalid JSON”.
This tool converts the failure into a JSON parse error line number and column, counted from 1 the way editors count, and pairs it with a statement of what the parser was expecting at that spot. A typical message reads Expected ',' or '}' (Line 4, Col 3). That is a JSON formatter with line and column error reporting, built for the moment you already know something is wrong and need to know where.
Two caveats. The position is where the parser gave up, which can be one character after the real mistake: a missing comma is reported at the start of the next key, not the end of the previous value. And a few rarer faults — an invalid backslash escape, a leading zero, a raw line break inside a string — are reported in the parser’s own wording rather than the tool’s.
4. The Eight Error Messages and the Mistake Behind Each
Each message maps to one or two habits that produce it.
Expected property name in double quotes
The usual message when the text came from code. You pasted an object literal from your source code or a Python dict, so the keys are unquoted or single-quoted. The rule is blunt: single quotes are not valid anywhere in JSON, so every key and string needs double quotes. It also appears when a trailing comma follows the last property, because the parser then expects another key and finds a closing brace.
Expected ',' or '}'
Two properties with no comma between them, or an object never closed. If the column points at the start of a key, the comma is missing from the line above.
Expected ',' or ']'
The array version of the same fault: two items with nothing between them, or a bracket never closed.
Expected ':' after property name
A key with no colon after it. Usually a typo, or YAML or a key=value config that was never JSON.
Unterminated string
A string that opened and never closed. Usually an unescaped double quote inside a value, or a response cut off mid-string.
Unexpected end of input
The text stopped where a value should begin: after a colon or a comma with nothing following. A response truncated mid-structure lands here or on Unterminated string; one cut off just after a value is reported as Expected ',' or '}' instead.
Unexpected token 'X'
A character that cannot start a value: a comment marker, NaN or undefined, a stray letter, or a trailing comma in an array followed by the closing bracket.
Unexpected trailing characters
A complete document followed by more text: two responses pasted back to back, a bracket typed twice, or debug output after the data.
The pattern is the same throughout: JSON is stricter than the language you copied it from. The tool is deliberately a reporter rather than a repairer, so what you copy out is only ever a reformatting of data that was already correct.
5. Minify, 4-Space or Tab Indent, and Sorting Keys
Once the banner is green, three controls decide what the output looks like. None of them change the data, which is the whole JSON minify vs beautify difference: the same values with different whitespace, read identically by any parser.
Minify
Click Minify and every line break and indent is removed. This is how to minify JSON for an environment variable or an HTTP body, and it is what people mean by “convert JSON to one line”.
Indent: 2, 4 or tab
Two spaces is the default. Pick 4 spaces when a style guide demands it, or format JSON with tabs when the codebase indents that way. The output pane updates as soon as you change the selection.
Sort Keys A-Z
Reorders every object’s keys alphabetically at every level of nesting, arrays included. Capital letters sort before lowercase. Off by default, so original key order is otherwise preserved.
If you need to sort JSON keys alphabetically online it is almost always because two files holding the same data will not diff cleanly. Run both through the tool with Sort Keys on and the same indent, and any remaining difference in a line-by-line compare is a real change in the values. There is no built-in diff; the sorted output is what you paste into whatever compare tool you already use.
This JSON minifier online offers no custom indent width beyond 2, 4 and tab, and no compact mode that keeps short arrays on one line. If the JSON has to go into a URL or a data attribute, minify here and then run the result through our Base64 encoder.
6. Keys, Depth and Bytes: The Readout on Valid JSON
When the input is valid, the green banner carries three figures people otherwise write a script for.
- Keys is the total number of object keys in the whole document, counted at every level and inside every array. To count keys in JSON online and sanity-check an export, this is the number.
- Depth is the deepest level of nesting, with the root value at 0. A flat object of strings has depth 1; an object holding an array of objects has depth 3. Use it as a JSON nesting depth checker before sending data to an API, database or search index that caps how deep a document may go.
- Size is the byte length of what you pasted. Compare it before and after Minify to see what whitespace was costing you.
This is a text box, not a viewer for very large documents. Ordinary API responses and config files are fine; a multi-megabyte paste will be slow to scroll, and there is no tree view to navigate it.
7. What Formatting Changes: Large Numbers, Duplicate Keys and Escapes
Formatting is not a find-and-replace on whitespace. The text is read into real values and written back out, and that round trip normalises a few things. Most pretty-printers do this; few say so.
- Whole numbers above 253 lose precision. If you searched JSON large number precision lost formatter because a nineteen-digit ID came out with different final digits, this is why. The precision available for JSON numbers is a limit RFC 8259 itself warns about. The fix at the source is to send long IDs as strings.
- Number spelling is canonicalised.
1.0comes out as1,1e2as100. The value is unchanged; the text is not. - Duplicate keys collapse. If an object lists the same key twice, only the last value survives, which is also how most parsers treat the file.
- Unicode escapes become characters. A
\u00e9in the input is written back asé; the string is identical, simply no longer escaped.
None of this matters for reading a response. It matters if the formatted text is going back into a system that compares bytes or signs payloads; there, treat the output as a readable view, not a replacement.
8. Why Cortexis Is the Best Free JSON Formatter
An error you can act on
Eight specific messages naming what the parser expected, each with a line and column instead of a character offset.
Free, with no sign-up
Searching for a JSON formatter no signup required? This is it: no email step and no output held behind a plan. Format, minify, copy and download are all available every time.
Private by default
A JSON formatter online private enough for real work. Nothing you paste is stored on our servers, retained after your session, or used for training.
Tab and 4-space indent
Pick 2, 4 or tab to match whatever style guide the file has to satisfy.
Deep key sorting
Sort Keys A-Z reorders every object at every level, which turns two differently-ordered files into something you can diff line by line.
Keys, depth and size at a glance
The valid-state banner reports key count, nesting depth and byte size without a script.
It sits alongside a wider set of free developer and document tools on the same terms, so you can encode and decode Base64, convert colour formats or generate a QR code without paying for any of it.
9. Frequently Asked Questions (FAQ)
Is this JSON formatter free and does it need an account?
Yes and no, respectively. It is a free online JSON formatter with no sign-up, no email and no plan that unlocks the download.
Why does my JSON say "unexpected token in JSON at position" and how do I find that line?
The position is a character offset, which is useless without counting. Paste the same text into the tool above and the red banner reports a line and column instead, along with what the parser expected there.
Why are single quotes not valid in JSON?
Because the standard only defines double-quoted strings. Single quotes are legal in Python and in most languages' object literals, which is why text copied from code fails with "Expected property name in double quotes". Change the quotes at the source; the tool reports the fault but does not rewrite it.
Does a trailing comma break JSON?
Yes. A comma after the last property or array item is a JSON trailing comma error, even though most programming languages allow it. In an object it is reported as "Expected property name in double quotes" at the closing brace; in an array it is reported as an unexpected token at the closing bracket.
What does "unexpected end of JSON input" mean?
The text ended before every open bracket or brace was closed: a truncated response, a clipped log line, or a copy that missed its last line. Paste it into the tool and it reports where the text ran out, as "Unexpected end of input" if it stopped before a value or "Expected ',' or '}'" if it stopped after one. Either way the line and column point at the very end, and the bracket that never closed is somewhere above.
Can I format JSON with 4 spaces or tabs instead of 2?
Yes. The Indent selector offers 2 spaces, 4 spaces or Tab. Click Format to rewrite your input at that width, then Copy or Download.
Can it fix broken JSON, show a tree view or convert to CSV?
No. It validates strictly and reports the first error; it does not repair trailing commas, single quotes, comments or JSON5. Both panes are plain text with no tree view or syntax colouring, and there is no conversion to CSV, XML or YAML. If you want to download formatted JSON file output rather than copy it, the Download button writes the formatted text as formatted.json.
Working with the data that surrounds JSON? The Base64 encoder and decoder unpacks the encoded payloads that hide inside a response, file renamer brings a folder of exported .json files into one naming scheme, and create archive bundles them into a single zip before you hand them over. To understand the APIs behind the data rather than simply tidy it, our free full-stack web development course builds and consumes JSON APIs from the first project onward.

