What the JSON Formatter does
JSON Formatter is two panes, an editor on the left and a read-only result on the right, with Format and Minify buttons beneath. Format parses the text and writes it out indented by two spaces per level, one property or array item per line. Minify parses it and writes it out with no spaces or line breaks at all. Copy, above the result, puts the result on the clipboard. Your input is never overwritten, so you can format, check, then minify from the same text.
Every action starts with a parse, which is what makes the tool a validator. If the text is not valid JSON, the result pane stays empty and the parser's error appears under the buttons. The message is produced by your browser's JSON engine, so its wording varies: Chromium-based browsers report something like Expected double-quoted property name in JSON at position 7 (line 1 column 8), while Firefox reports a line and column in its own words. Only the first error is reported.
The parser is strict in the sense of RFC 8259. Property names and strings must use double quotes, there are no comments, no trailing commas and no undefined or NaN values. The top-level value can be an object, an array, a string, a number, true, false or null, so a bare array from an API or a single quoted string is accepted.
Because the output comes from JSON.stringify, it is a re-serialisation of the parsed data rather than a whitespace-only edit of your text. For most documents that makes no visible difference beyond indentation, but numbers, escapes and duplicate keys are normalised in ways worth knowing before you paste a formatted file back into a repository.
How to use it
Paste the JSON
Any single JSON value works: an object, an array, a string, a number or a literal. The placeholder shows the smallest useful example, {"hello":"world"}.
Press Format or Minify
Format gives two-space indentation; Minify collapses everything to one line. If the text does not parse, the error appears below, the result pane stays empty and the editor is left as it was.
Copy the result
Copy, above the result pane, places the result on the clipboard. There is no download button, so paste it into your editor, terminal or request body.
What the validator accepts and rejects
The grammar is the one in RFC 8259 and on json.org: objects of name-value pairs, arrays, strings in double quotes with backslash escapes, numbers in decimal or exponent form, and the literals true, false and null. Anything a JavaScript object literal allows beyond that is rejected: unquoted keys, single-quoted strings, trailing commas after the last item, comments, hexadecimal numbers, leading plus signs and the values undefined, NaN and Infinity.
Empty input is also an error, reported as Unexpected end of JSON input. The same message appears when a paste was cut short, which usually means a closing bracket or brace is missing at the end. The quickest fix for files that use JSON with comments, such as tsconfig.json or editor settings, is to delete the comments before formatting; JSONC is a different format from JSON.
How the output can differ from the input
Numbers pass through JavaScript's double-precision representation. Integers above 9007199254740991, the largest safe integer, are rounded: 9007199254740993 comes out as 9007199254740992. If your data carries 64-bit identifiers as bare numbers, keep them as strings before formatting, or format a copy and never paste the result back over the source. Other number spellings are normalised too: 1.0 becomes 1, 1E2 becomes 100 and -0 becomes 0.
Strings are re-escaped. A Unicode escape such as \u00e9 is written back as the literal character é, while control characters, quotes and backslashes keep their escapes. Duplicate property names collapse to the last value, because a JavaScript object can hold a name only once; RFC 8259 says names should be unique, so a document that relied on duplicates was already fragile. Property order is preserved except that names which look like non-negative integers are moved to the front in ascending numeric order, which is how JavaScript orders object keys.
- Large integers: rounded beyond 9007199254740991
- 1.0, 1E2, -0: written as 1, 100 and 0
- \u escapes for printable characters: replaced by the character itself
- Duplicate keys: only the last value survives
- Integer-like keys: sorted to the front
Reading the error message
In Chromium-based browsers the position is a zero-based character offset from the start of the text, followed by a line and column. The four most common causes, in rough order, are a trailing comma after the last property, single quotes copied from a Python or JavaScript literal, an unquoted key, and a comment left over from a JSONC file. Fix the reported spot, press Format again, and repeat until the message changes to Valid JSON formatted; because only the first error is reported, a file with several faults takes several rounds.
When to minify and when to format
Minified output has no whitespace at all, which is what you want for a value stored in an environment variable, embedded in a query string or sent as a compact request body. Formatted output is for reading, reviewing in a diff and committing to a repository. The indentation is fixed at two spaces; there is no tab or four-space option and no key sorting, so if your project enforces a different style, run the result through your own formatter afterwards.
Limits to know before you rely on it
- Only the first syntax error is reported, and its wording comes from your browser's JSON parser, so it differs between Chrome, Firefox and Safari.
- Integers larger than 9007199254740991 are rounded because the formatter works through JavaScript numbers; keep identifiers of that size as strings.
- Comments, trailing commas, single quotes and other JSON5 or JSONC extensions are rejected. This is a strict RFC 8259 formatter.
- Indentation is fixed at two spaces. There is no option for tabs or four spaces and no key sorting.
- The tool checks syntax only. It does not validate against a JSON Schema or check that particular fields exist.
- There is no download button; copying to the clipboard is the only way to export the result.
Questions people ask about the JSON Formatter
Why does it say Unexpected end of JSON input?
The editor is empty or the text stops before the value is complete. The usual cause is a paste that was truncated, leaving a closing bracket or brace missing at the end. Scroll to the bottom of the editor and add the missing character, then press Format again.
Does formatting change my data?
It changes the whitespace and, in a few cases, the spelling of values. Integers above 9007199254740991 are rounded, 1.0 becomes 1, Unicode escapes for printable characters become the characters themselves, and duplicate keys keep only the last value. Everything else parses to the same data before and after.
Can I format JSON that contains comments, such as tsconfig.json?
Not directly. Comments are not part of JSON, so the parser stops at the first one and reports its position. Delete the comment lines, format, and add the comments back afterwards, or use an editor that understands JSONC for that file.
Is a bare array or a single string valid input?
Yes. RFC 8259 allows any JSON value at the top level, so [1, 2, 3], "hello" and 42 all format without complaint. Older specifications required an object or array at the top, which is why some tools reject these.
Why did my numeric keys move to a different position?
JavaScript orders object properties with integer-like names first, in ascending numeric order, before the remaining names in insertion order. A key such as "10" or "2" will therefore appear before "name" in the output. The data is unchanged; only the order of the keys differs.
Is the JSON I paste sent anywhere?
No. Parsing and formatting are done by your browser's built-in JSON functions on the page itself. Nothing is sent to a server or stored, and the editor is empty again after a reload.
Sources and further reading
- RFC 8259, The JavaScript Object Notation (JSON) Data Interchange Format: the grammar the parser enforces, the rule that names should be unique, and the interoperability note on numbers
- MDN Web Docs, JSON.parse(): the function behind Format and Minify, including what counts as a SyntaxError
- MDN Web Docs, JSON.stringify(): the space argument used for two-space indentation and how values are serialised
- MDN Web Docs, Number.MAX_SAFE_INTEGER: why integers above 9007199254740991 lose precision