JSON Formatter and Validator

Paste JSON to learn whether it is valid and, when it is not, which line and column break the rules. Valid JSON comes back indented the way you choose or squeezed onto one line, ready to copy or download. Everything happens inside this browser tab, so API keys and private payloads stay on your machine.

0 B of 5 MB

Limits: Up to 5 MB of JSON. Larger input is refused with a message.

Results

Result
-
Top level
-
Nesting depth
-
Values
-
Output size
-
Error at
-

How to use the JSON Formatter and Validator

  1. Paste the JSON into the box, or press Load the example to try a sample order.
  2. Choose an output style: indented with 2 spaces, 4 spaces or tabs, or minified.
  3. Read the result. An error names its line and column and marks the spot with a caret.
  4. Copy the formatted JSON, or download it as formatted.json.

Worked example

A small order record from an online shop, written on one line the way an API often returns it. Press Load the example to indent it with 2 spaces. The page also notes that 4.50 and 12.00 come back as 4.5 and 12, since JSON.parse keeps the number and not the way it was written.

{"order":1042,"customer":{"name":"Ana Souza","email":"ana@example.com"},"items":[{"sku":"TEA-01","qty":2,"price":4.50},{"sku":"MUG-03","qty":1,"price":12.00}],"paid":true}
Output style
Indented, 2 spaces
Sort keys A to Z
off
Result
Valid JSON
Top level
Object, 4 keys
Nesting depth
3
Values
15
Formatted JSON
{ "order": 1042, "customer": { "name": "Ana Souza", "email": "ana@example.com" }, "items": [ { "sku": "TEA-01", "qty": 2, "price": 4.5 }, { "sku": "MUG-03", "qty": 1, "price": 12 } ], "paid": true }

How to read the results

Result
Valid JSON or Not valid JSON, decided by your browser's JSON.parse.
Top level
What the whole text is: an object with its number of keys, an array with its number of items, or a single string, number, true, false or null, which JSON also allows.
Nesting depth
How many objects and arrays sit inside one another at the deepest point. A flat object is 1.
Values
Every object, array, string, number, true, false and null in the text, containers included. Keys are not counted.
Output size
The formatted or minified text in UTF-8 bytes, the size it has as a file.
Error at and Where the error is
For invalid input, the line and column of the first character the grammar does not allow, and that line with a caret under it. Columns count characters, so an emoji counts once.
Notes above the results
A yellow note means the output differs from your text in meaning: a rounded number, a number turned into null or a dropped duplicate key. A blue note means only the writing changed, such as 1.50 printed as 1.5 or keys that moved.

How this tool works and its limitations

The text goes to JSON.parse, and that alone decides whether it is valid. When it fails, the error message is not used, because each browser words it differently and some give no position. A small scanner instead reads the text one character at a time by the grammar of RFC 8259 and stops at the first character that cannot belong there, which gives the line, the column and a message written by this page. A line ends at a line feed, a carriage return or both together.

Valid text is scanned once more to compare each number as written with what JSON.parse made of it, to find repeated keys and to see whether whole number keys will move, as the ECMAScript key order rule puts them first. The output is written from the parsed value with JSON.stringify, or with a writer of the same format when keys are sorted or the nesting is too deep for JSON.stringify. Nothing is uploaded or stored, and these limits apply:

  • The output is written from what JSON.parse returns, so whole numbers above 9007199254740991 lose their last digits, numbers beyond about 1.8e308 become null, and decimals are rounded to the nearest 64 bit value. The page warns and quotes the first case.
  • When a key repeats inside one object, only its last value survives in the output, as the ECMAScript standard requires; the first copy keeps its place in the order.
  • Keys that are whole numbers move to the front of their object unless you sort, because JavaScript objects always list them first.
  • Comments, trailing commas, single quotes and other JSON5 or JavaScript extras are reported as errors, never repaired.
  • The scanner stops at the first error only. Fix it and the next one, if any, appears.
  • Input is capped at 5 MB. The slowest file we have measured is a 4.9 MB one written on a single line that ends with 1,000 examples of every note this page gives; in Chromium on the test machine it was checked and formatted in one step of about 130 ms (180 to 260 ms with sorted keys), starting 350 ms after the paste. The page does not respond while that step runs, and a slower computer or phone takes longer. A result longer than 100,000 characters shows only its start in the box; Copy and Download take all of it.

Features

  • Validation by JSON.parse itself, the same parser your JavaScript code calls.
  • Error positions found by a scanner that follows the JSON grammar, so the line and column read the same in every browser.
  • Warnings for numbers too big to keep exactly, keys listed twice and keys that change places.
  • Optional key sorting for stable diffs, with arrays left in their original order.

Why JSON that looks fine still fails

Most broken JSON is JavaScript that looks close enough. RFC 8259, the JSON standard, has no comments, no trailing commas, no single quotes and no unquoted property names, and its only bare words are true, false and null, so NaN and undefined fail as well. MDN's JSON.parse page shows a trailing comma throwing a SyntaxError, and the ECMAScript standard forbids browsers from accepting any extended grammar. Config files that allow comments are often JSON5, a separate format made for writing by hand. Remove the extras before a program parses the file.

Large numbers and repeated keys change without an error

JSON.parse stores every number as a 64 bit float. Section 6 of RFC 8259 promises interoperability only for whole numbers between minus and plus 9007199254740991 (2^53 minus 1), so an order ID such as 12345678901234567890 comes back as 12345678901234567000 and nothing complains. Send IDs that long as strings. Keys are similar: the RFC says names SHOULD be unique and that many parsers keep only the last pair, and ECMAScript requires exactly that. A payload with two "price" keys therefore reaches your code with one price, and this page tells you which.

Indent, minify or sort: pick by where the JSON goes

Two space indentation keeps deeply nested files narrow, while four spaces or tabs suit teams whose editors are set that way. Minified JSON drops every optional space and line break, which saves bytes in an API response or a data attribute, although a server that compresses its responses already shrinks runs of spaces, so the saving on the wire is often smaller than the file size suggests. Sorting keys helps when you compare two versions of a file, because the same data always prints in the same order. It does change the order your file had, so leave it off when the order carries meaning to a reader.

Frequently asked questions

What is the difference between formatting and validating JSON?

Validating answers one question: does the text follow the JSON grammar? Formatting rewrites valid JSON with the spacing you choose. This page always validates first, because invalid text has no structure to format.

Why does the error point at a character after the real mistake?

A parser only notices a problem when the next character cannot fit. A missing comma between two items is reported at the start of the second item, and a missing closing bracket is reported at the end of the text. Look just before the caret as well.

Can it fix my JSON automatically?

No. Guessing where a quote or bracket belongs can silently change the data, so the tool names the problem and leaves the edit to you. Most fixes are one character: a comma, a quote or a bracket.

Is my JSON sent to a server?

No. The page parses and formats the text with the JavaScript engine in your own browser and makes no request with it. Nothing is stored after you close the tab.

Why did my long numbers change?

JavaScript keeps numbers as 64 bit floats with about 16 significant digits. Longer whole numbers are rounded to the nearest value that fits, so the output shows the rounded value. If the exact digits matter, the producer of the JSON should send them as strings.

Does key order matter in JSON?

The standard treats an object as unordered, so two objects with the same keys and values mean the same thing. People and some tools still read the order, which is why sorting is an option and never the default.

Last updated .