JSON formatter and validator
Paste JSON to format and validate it online. The check runs as you type, an error shows its exact line and column, and Repair fixes trailing commas, quotes and comments. Nothing is uploaded.
How to use it
- Paste JSON, drop a
.jsonfile on the box or press Open file. The check runs as you type. - Pick the indentation: 2 spaces, 4 spaces, a tab, or Minify for a single line.
- If the JSON is invalid, read the line and column, press Go to error, or press Repair to fix common mistakes.
- Copy the result or download it as
formatted.json.
What makes JSON valid
JSON is defined by RFC 8259 (December 2017), an Internet Standard, and by ECMA-404, which describes the same grammar. The rules are short. A value is an object, an array, a string, a number, or one of three literal names: true, false, null, all in lower case. Strings and object keys are wrapped in double quotes. Numbers are written in base 10, without leading zeros, and NaN and Infinity are not permitted. The grammar has no comments and no comma before a closing bracket.
These are the mistakes the validator meets most often, and what Repair writes instead:
| Input | Why it is invalid | After Repair |
|---|---|---|
[1, 2,] | A comma must be followed by another value | [1, 2] |
{'a': 1} | Strings need double quotes | {"a": 1} |
{a: 1} | A key is a string, so it needs quotes | {"a": 1} |
{"a": 1} // note | JSON has no comments | {"a": 1} |
{"ok": True} | Literal names are lower case | {"ok": true} |
{"x": NaN} | NaN and Infinity are not JSON numbers | {"x": null} |
Reading the error position
A parser reports the first character it cannot accept, which is often just after the real mistake. A missing comma between two keys is reported at the start of the second key, because that is where the parser expected a comma or a closing brace. A trailing comma is reported at the bracket that follows it. If the message says the text ends too early, a bracket or a quote was opened and never closed; look for it above the reported line.
Raw line breaks and tabs inside a string are another common cause. RFC 8259 requires the control characters U+0000 to U+001F to be escaped, so a value copied out of a log with a real line break in it must be written with \n instead.
Format, minify and validate: what changes
Formatting and minifying change only whitespace: Minify removes every space and line break outside strings. RFC 8259 allows spaces, tabs, line feeds and carriage returns around the six structural characters [ ] { } : ,, and nothing else in the file moves. The same small record shows the difference:
| Setting | Size | Lines |
|---|---|---|
| Minify | 44 bytes | 1 |
| Tab | 62 bytes | 8 |
| 2 spaces | 70 bytes | 8 |
| 4 spaces | 86 bytes | 8 |
What Repair fixes
Most invalid JSON is a JavaScript object, a Python dictionary or a log line pasted as is. Python’s own json.dumps, for example, writes NaN and Infinity unless you pass allow_nan=False, and its documentation says those values are outside the JSON specification. Repair reads such text loosely and writes strict JSON, then lists every kind of change it made, so nothing changes without you seeing it.
- Trailing commas, missing commas and missing colons
- Single quotes, curly quotes and keys without quotes
//,/* */and#comments- Python
True,False,None; JavaScriptundefinedandNaN - Numbers such as
+1,.5and0x1F - A Markdown code fence, a JSONP wrapper, a byte order mark
- Brackets and quotes left open at the end of a cut-off response
Long numbers stay exact
RFC 8259 notes that integers between −(253)+1 and (253)−1 are interoperable, because most software stores numbers as 64-bit floating point. Formatters that run your text through JSON.parse and back round anything larger: an ID such as 12345678901234567890 comes back as 12345678901234567000. This formatter never converts numbers. It keeps the digits exactly as written, and so do the JSON viewer, the JSON diff and JSON to CSV.
Large files and limits
Files up to 64 MB open here. Above 200 KB the work moves to a background thread so the page keeps responding, and text above 2 MB is not put in the edit box, because a multi-megabyte text box freezes typing in every browser. The result pane shows the first 1 MB; Copy and Download always give you the whole result. Nesting deeper than 5,000 levels is reported as an error instead of crashing the tab.
To read a big file rather than reformat it, open it in the JSON viewer, which draws only the branches you open. For a command line, Python ships the same job as python -m json.tool file.json.
Related tools
Questions people ask
Is my JSON sent to a server?
No. Parsing, formatting and repair run in your browser, and nothing you paste or open leaves your device.
What is the difference between a JSON formatter and a JSON validator?
A validator checks the text against the JSON grammar and reports the first error. A formatter rewrites valid JSON with consistent indentation. This page does both: it validates on every keystroke and formats once the text is valid.
Why is my JSON invalid when JavaScript accepts it?
JSON is stricter than JavaScript: keys and strings need double quotes, and comments, trailing commas, single quotes and undefined are not allowed. Repair converts these.
Can JSON have comments?
No. The grammar in RFC 8259 has no comment syntax. Some tools read a variant with comments, such as the “JSON with Comments” mode of VS Code settings files, but a strict parser rejects it. Repair removes the comments.
Are duplicate keys allowed?
RFC 8259 says names within an object SHOULD be unique, and that software receiving duplicates behaves unpredictably: many keep the last value. This formatter keeps both entries as written so you can see and remove one.
Does Sort keys change my data?
No. RFC 8259 defines an object as an unordered collection, so key order carries no meaning. Array order is kept as it is.
Can Repair invent missing data?
No. It only removes what JSON does not allow, adds the punctuation that is missing and closes what was left open. If text cannot be read even loosely, it stops and shows where.