ToolsWhisper
Developer tools

JSON Formatter & Validator

Pretty-print, minify and validate JSON with precise error positions.

  • Runs in your browser
  • Nothing is uploaded
  • Free, no sign-up
Mode
JSON input
Formatted

Valid JSON. Only whitespace was changed; every value is exactly as you wrote it.

About this tool

Paste raw JSON to reformat it with consistent indentation, or minify it down to a single line. If the document will not parse, the exact line and column of the problem is reported instead of a generic failure.

How to use it

  1. Paste or type your JSON into the input pane.
  2. Choose an indent width, or switch to Minify to strip all whitespace.
  3. Copy the formatted output or download it as a .json file.

The four errors that cause almost every failure

Invalid JSON is nearly always one of a handful of mistakes. JSON is a much stricter format than the JavaScript object literals it resembles, and that gap is where people get caught.

Trailing commas. Perfectly legal in modern JavaScript, illegal in JSON:

{ "name": "Ada", "role": "engineer", }

Single quotes. JSON requires double quotes on both keys and string values. {'name': 'Ada'} is a valid JavaScript object and invalid JSON.

Unquoted keys. {name: "Ada"} parses fine in a browser console but fails here — every key must be a quoted string.

Comments. JSON has no comment syntax at all. If your config file contains // or /* */, it is JSONC or JSON5, not JSON, and needs a parser that understands those.

Why the error says line and column

Browsers report JSON errors as a character offset — "position 1847" — which is useless when you are looking at a 400-line file.

This tool converts that offset into a line and column, and where the browser reports no offset at all it locates the surrounding snippet and names the line instead. Either way you get somewhere to look rather than a number to count to.

What formatting changes, and what it never does

Formatting here changes whitespace only. The tool reads your JSON as text instead of converting it into JavaScript values and printing them back, so nothing in the data is rewritten:

  • Numbers keep every digit. 12345678901234567890 stays exactly that, not 12345678901234567000. And 10.50, 1.0 and 1e3 are not "tidied" into 10.5, 1 and 1000.
  • Strings are untouched. Escape sequences such as \u00e9 and \/ stay as written.
  • Key order and duplicate keys are kept. {"b":1,"2":2,"1":3} keeps its order, and a repeated key is not silently dropped. Both are valid JSON that different parsers treat differently, which is exactly why a formatter should not decide for you.
  • A leading byte-order mark is removed. It is invisible, and some parsers reject an otherwise valid file because of it.

The one deliberate exception is Sort keys A–Z, which reorders keys because you asked it to.

Most tools that reformat JSON parse it into JavaScript values and print those back out, and that is where the surprises come from: integers beyond 9,007,199,254,740,991 lose digits, duplicate keys collapse, and integer-like keys jump to the front. If a value has to survive exactly, this tool will not alter it. Signed documents are still best left alone, because any reformatting changes the bytes a signature covers.

More errors worth recognising

Beyond the four common ones above, these turn up in real files:

  • A byte-order mark. Some editors put an invisible character at the very start of a file. The file looks fine and fails immediately with an "Unexpected token" error on line 1.
  • NaN, Infinity and undefined. JavaScript has them and JSON does not. If one is in your data, a serialiser upstream produced invalid output.
  • Leading zeros and plus signs. 007 and +1 are not valid JSON numbers.
  • A raw line break inside a string. Newlines and tabs in a string must be written as \n and \t. A literal one is reported as a bad control character.
  • More than one document. Two objects back to back, or a JSON Lines file with one object per line, are not a single JSON document. The error points at the start of the second object. Format one line at a time, or wrap them in an array.

Indent, minify and sort keys

Indent. Two spaces is the most common convention for JSON. Four spaces and tabs are there for projects whose style guide asks for them.

Minify. Removes every space and newline that is not inside a string, and tells you how many characters that saved. Minify for payloads and storage, and format for reading.

Sort keys A–Z. Sorts the keys of every object, at every depth. Arrays keep their order, because the order of an array is data. Sorting is most useful before comparing two documents: sort both, paste them into the diff checker, and differences that came only from key order disappear.

Large and sensitive documents

Everything runs in your browser, so the document never leaves your device. That makes the tool reasonable for payloads that contain customer records, tokens or keys, and you can confirm it in the Network tab of your developer tools. Parsing happens on the page's main thread, so a document of many megabytes can make the tab unresponsive for a moment.

If you are looking at a JWT, its payload is JSON too, and the JWT decoder reads the whole token for you. Valid JSON can also still be the wrong shape, which is a different check: see syntax versus schema validation.

To move the data into another shape, JSON to CSV flattens arrays of objects into rows, and YAML to JSON converts configuration files in either direction. If something that works in JavaScript fails here, JSON vs JavaScript objects lists the differences.

Frequently asked questions

Why does my JSON fail to validate?

The most common causes are trailing commas, single quotes instead of double quotes, and unquoted object keys. All three are valid JavaScript but invalid JSON. The error message points at the offending line and column.

Can it handle very large files?

Yes, within your browser's memory. Documents of a few megabytes format instantly; extremely large files may take a moment since parsing happens on the main thread.

Is my JSON sent to a server?

No. Parsing and formatting happen in your browser via JSON.parse, so even production payloads containing customer records or API keys stay on your machine.

Does formatting change my data?

No. Only whitespace changes. Numbers, strings, key order and duplicate keys are kept exactly as you wrote them, so long IDs and exact amounts survive. The only reordering that can happen is the Sort keys option, which you choose.

Does it validate against a JSON Schema?

No. It checks syntax, meaning whether the text is valid JSON. Checking that the data has the right fields and types needs a schema validator. The difference is explained in the article on syntax versus schema validation.

Is JSON with comments valid?

No. Standard JSON has no comments. Files that contain them are usually JSONC or JSON5 and need a parser that understands those formats. Remove the comments before validating here.

Articles using this tool

Related tools