How a JSON formatter works
A JSON formatter reads your text, checks that it follows the JSON grammar, and writes it out again with new spacing. Only the whitespace changes, which is why the same parse can pretty print, minify and validate.
The grammar, set by RFC 8259, is short. The
browser's built-in
JSON.parse
gives the yes or no; because its error messages differ between browsers, this page also runs its own reader to
explain what went wrong and give the exact line and column.
Unlike a plain JSON.stringify round trip, this tool keeps every number and string exactly as written, so
12345678901234567890 is not silently rounded.
What are the six JSON data types?
| Type | Example | Rules |
|---|---|---|
| Object | {"id": 7} | Keys are strings in double quotes, followed by a colon. Keys should be unique. |
| Array | [1, "two", null] | Ordered list. Items can be of mixed types. |
| String | "caf\u00e9" | Double quotes only. Quotes, backslashes and line breaks must be escaped. |
| Number | -12.5e3 | No leading zeros, no plus sign, no NaN or Infinity, no hex. |
| Boolean | true | Lowercase true or false. |
| Null | null | Lowercase. The only way to say "no value". |
Source: RFC 8259, sections 2 to 7.
There is no date type, no comment syntax and no way to write undefined. Dates travel as strings,
usually in ISO 8601 form, or as a Unix number that our Unix timestamp converter turns into a readable date, and a missing value is either left out or written as null.
What are the most common JSON errors, and how do you fix them?
| Error | Looks like | Fix |
|---|---|---|
| Trailing comma | {"a": 1,} | Delete the last comma |
| Single quotes | {'a': 'x'} | Use double quotes |
| Unquoted key | {a: 1} | Write "a" |
| Missing comma | {"a": 1 "b": 2} | Add a comma between the pair |
| Comment | {"a": 1 // note} | Remove it; JSON has no comments |
| Leading zero | [007] | Write 7, or quote it as "007" |
| Bad literal | [True, NaN, undefined] | Use true, or null instead |
| Raw line break | "line one line two" | Write \n inside the string |
| Extra content | {"a":1} {"b":2} | Wrap the two values in an array |
How do you read the error pointer?
The caret sits under the character where the reader gave up; where a piece is missing, it sits on the next thing the reader saw.
Counting starts at 1 and each tab counts as one column. A line that was minified onto a single row has only one line number, so use the column and the caret excerpt to find the spot.
When should you pretty print, use tabs or minify?
The same small object in each layout:
| Layout | Lines | Size |
|---|---|---|
| Minified | 1 | 73 bytes |
| 2 spaces | 10 | 107 bytes |
| 4 spaces | 10 | 127 bytes |
| Tab | 10 | 97 bytes |
Source: Sizes in UTF-8 bytes. Deeper nesting makes the gap between pretty and minified larger.
Use 2 or 4 spaces for files people read and review, and minify when nobody will read the file by eye.
Sort keys reorders every object's keys alphabetically by character code, at all depths, and leaves arrays alone because their order carries meaning. Two objects that hold the same data then print identically, which makes them easy to compare in our text compare tool.
Common mistakes
- Pasting a JavaScript object and expecting it to be JSON. Code like
{name: 'Dana'}is valid JavaScript but has two JSON errors: an unquoted key and single quotes. - Large numbers in IDs. The standard warns that numbers beyond the range of a 64-bit float may not be read back exactly by other software. According to MDN, JavaScript's largest safe integer is 9,007,199,254,740,991. Send bigger IDs as strings. This page warns you when it sees one.
- Duplicate keys. They are legal to write but unreliable to read: the standard says names should be unique, and
JSON.parsekeeps only the last. This page leaves both in place and lists them as a warning. - An invisible first character. A byte order mark at the start of a file makes browsers reject otherwise valid JSON. The error card names it so you can delete it.
- Several JSON values in one file. Log files often hold one object per line (JSON Lines). That is not a single JSON document. Wrap the lines in
[ ]and add commas to make it one. Binary or encoded fields are often wrapped in Base64; our Base64 encoder and decoder unwraps them.
Common questions
Is it safe to paste private JSON here?
The text is processed in your browser tab and the page sends it nowhere; the site does count page views. Keep secrets out of any pasted text anyway, and use our online notepad for scratch text you want to keep in this browser.
Can JSON have comments?
No. JSONC and JSON5 allow comments but are not JSON; strip them before validating.
Is a lone number or string valid JSON?
Yes. Since RFC 7159 (2014) and in RFC 8259, a JSON text can be any value, not only an object or array, so
42 and "hello" are valid.
How big a file can it handle?
Several megabytes format in well under a second on a current laptop; the colored view switches to plain text above about 250,000 characters.
Sources
- IETF RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format
- Ecma International: ECMA-404, The JSON Data Interchange Syntax
- MDN Web Docs: JSON.parse()
- MDN Web Docs: JSON.stringify()
- MDN Web Docs: SyntaxError, JSON.parse: bad parsing
- MDN Web Docs: Number.MAX_SAFE_INTEGER
Last reviewed November 9, 2026.