ToolsHub4u

Format, validate and inspect JSON

Paste JSON to format or minify it. Large integers keep every digit, 1.0 and 1e3 keep their spelling, and duplicate keys are reported.

  • Live validation
  • Line and column errors
  • Nothing uploaded
Ready Developer & Utility
1Enter
2Adjust
3Copy result

JSON Formatter & Validator

1

JSON input

Paste an object, array or single value. A byte-order mark at the start is ignored.

No data yet Live
2

Formatted JSON

Valid JSON. Formatted from 113 to 162 characters.

Formatted JSON

  • Syntax is valid JSONThe text parsed with the browser's built-in JSON parser. No trailing commas, comments or unquoted keys were found.
  • Duplicate keys cannot be detected hereWhen a key appears twice, JSON.parse keeps the last value. Use a linter if duplicate keys matter.
  • Nesting depth is 2Very deep structures are valid JSON but hard to read and may hit limits in other parsers.
Characters
162
Keys
7
Objects
2
Arrays
1
Depth
2
Characters added
49

Formatting only changes whitespace. Minifying and sorting do not change values. Both JavaScript and Node reject NaN, Infinity and comments, so they are rejected here too.

This page validates JSON and writes it back in a readable or compact form. Paste an object, an array or a single value, choose Format or Minify, pick an indentation and optionally sort keys. If the text is not valid JSON, the result gives a line, a column and a short message instead of a formatted document.

Validation uses a strict parser written for this page. It follows the JSON grammar, so a document that passes here is valid JSON and will parse in a browser or in Node. That also means the rules are strict: no trailing commas, no comments, no unquoted keys and no single-quoted strings.

Validation and formatting

A valid document is rewritten with the chosen indentation: two spaces, four spaces or a tab. Each key and value pair goes on its own line, arrays put each element on a line, and the closing brace or bracket returns to its parent's level. A byte-order mark at the very start is ignored, because files saved by some Windows tools include one.

An invalid document produces a failure with a line and a column, taken from the position the parser stopped at. That is usually enough to find a trailing comma, a missing quote or a stray character. For example, a comma after the last member of a three-line object is reported at line 3, column 1, and a single-quoted key at line 1, column 2. The page does not try to repair the input, because guessing at a broken document is how data gets corrupted.

Formatting changes whitespace and, when you ask for it, key order. It does not change the text of a number or a string: those tokens are copied from your input rather than rebuilt from a parsed value. The next sections explain why that matters.

Minify, sort and indentation

Minify removes all optional whitespace and writes the document on one line. It is useful before embedding JSON in a URL, a header or a config value where line breaks are awkward. The stats show zero characters saved if the input was already compact.

Sort object keys alphabetically reorders the keys of every object, including nested ones. Arrays keep their order, because array order is data rather than naming. Sorting is convenient for comparing two documents by eye, but it changes the output order, which matters if something downstream depends on key order or on the original formatting.

Indentation has no effect in minify mode, where everything is on one line. In format mode, a tab produces a more compact file than four spaces but renders differently in different viewers. Two spaces is the common choice for source files and diffs.

A worked example

A 113-character object with a nested object and an array was formatted with two spaces and no sorting. The output was 162 characters, with 7 keys, 2 objects, 1 array and a nesting depth of 2.

Results for four JSON inputs
InputActionResult
113-character objectFormat, 2 spaces162 characters, 7 keys, depth 2
Same objectMinify113 characters, 0 saved
Two large integers, 61 charactersFormat, 2 spaces70 characters, every digit unchanged
Object with a repeat key, 19 charactersFormat, 2 spaces22 characters, a reported, value 3 kept

The formatted output put each key on its own line and expanded the array so each string had a line. The nested owner object gained a second level of indentation. Nothing was reordered, and the null contact value stayed null.

The minified run returned the original 113 characters because the sample was already compact. That is the correct result, not a failure, and the stats say 0 saved rather than inventing a reduction.

A trailing comma is the most common errorJSON does not allow a comma after the last member. The page points at the position it could not accept, which is usually the line after the comma, so check the end of the previous line first.

Numbers and strings keep their exact text

Most JSON tools parse a number into a JavaScript double and write it back from that value. That is where digits go missing: integers above 253 are rounded, 1.0 becomes 1, and 1e3 becomes 1000. This page does not take that step. It reads the number token as text and writes the same characters back.

In testing, 9007199254740993 came back unchanged, and so did a 30-digit integer. 1.0, 1e3, 1E+3, -0 and 0.10 all kept their original spelling. A 64-bit identifier copied from a database therefore still points at the same record after formatting.

Strings behave the same way. The escape sequences you paste are preserved, so a\/b, caf\u00e9 and say \"hi\" keep their form rather than being decoded and re-escaped. The trade-off is that this page checks the syntax of a number but does not evaluate it, so it cannot tell you whether the value fits a JavaScript number. If another program will read the JSON with JSON.parse, keep large identifiers as strings there.

Duplicate keys and the stats

Duplicate keys are found and reported. When a key appears twice in the same object, the last value is kept, which is what JSON.parse does; the earlier value is dropped. The checklist names up to four repeated keys and the warning line repeats the full list, so a silent overwrite becomes visible. That is a detection and a report, not a repair: the output still contains one value per key.

Keys counts unique property names, including nested ones. Objects and arrays count the containers, and depth is the maximum nesting level, with a top-level scalar at 0 and a flat object at 1. The character count is the length of the output string, so it includes indentation and line breaks.

For a structural view rather than a text view, a dedicated JSON viewer with a collapsible tree is easier. For comparing two documents, format both with the same settings and use the code diff checker. This page does not convert JSON to XML, CSV or YAML; keep a separate converter for that job.

Questions

Common questions

Short answers about this tool and its limits.

Are large integers still rounded?

No. A number is copied as text rather than parsed into a JavaScript double, so 9007199254740993 and a 30-digit integer come back with every digit. If another program reads the result with JSON.parse, that program can still round it, so keep very large IDs as strings when the consumer is JavaScript.

Does 1.0 stay 1.0?

Yes. 1.0, 1e3, 1E+3, -0 and 0.10 all keep their original spelling, because the number token is not evaluated and rebuilt.

Are duplicate keys detected?

Yes. The page counts repeats, names up to four of them in the checklist, and repeats the full list in the warning. The last value wins, matching JSON.parse, so an earlier value is dropped rather than kept in the output.

Does sorting keys change the values?

No. It reorders keys alphabetically at every level and leaves values, number spellings and array order alone. The output order changes, so do not sort if a downstream tool depends on the original order.

Why is a trailing comma rejected?

JSON does not allow a comma after the final member of an object or array. JavaScript object literals do, which is why the habit carries over. Remove the comma and validate again.

Can I paste JSON with comments?

No. Comments are not part of JSON and the parser rejects them. If you need comments, the data belongs in a format such as JSONC or YAML, not in a .json file.

What does depth mean?

It is the maximum nesting level. A top-level scalar has depth 0, a flat object has depth 1, and an object containing an object has depth 2. Deep nesting is valid but harder to read and may hit limits elsewhere.

Is my JSON uploaded?

No. Parsing and formatting run in the browser with no account or server copy. Nothing is stored, so copy or download the result before leaving the page.