Developers

JSON Formatter and Validator

Pretty-print, minify and validate JSON locally, with precise error locations and a warning for numbers JavaScript cannot store exactly.

Runs in your browser — nothing is uploaded

Loading the tool…

What this JSON formatter does

JSON is the format most web APIs, configuration files and data exports use, but it often arrives as a single unreadable line or with a syntax error somewhere in thousands of characters. This tool turns that into something you can read and trust: it pretty-prints JSON with 2-space, 4-space or tab indentation, minifies it back to the smallest valid form, and validates it, telling you exactly where an error sits.

It is built for developers inspecting an API response, testers comparing payloads, data analysts opening an export, and anyone editing a configuration file such as package.json or a settings file who wants to be sure it is still valid before saving it.

How to use it

  1. Paste or type JSON into the input area, or open a .json file from your computer. The file is read locally by your browser.
  2. Pick an indentation style: 2 spaces, 4 spaces or a tab. Tick “sort keys alphabetically” if you want object keys in a stable order.
  3. Click Format to pretty-print, Minify to remove all unnecessary whitespace, or Validate to simply check the syntax.
  4. If the JSON is invalid, read the error message: it gives the line and column of the problem, and the offending line is highlighted in the input.
  5. Review the result in the output panel, which shows line numbers and the size of both input and output.
  6. Click Copy to put the result on your clipboard, or Download to save it as a .json file.

Typical use cases

  • Reading an API response: paste the compact body returned by curl or your browser's network panel and format it to see the structure at a glance.
  • Finding a syntax error: a configuration file refuses to load; the validator reports, for example, an unexpected character at line 14, column 3, which is usually a trailing comma or a missing quote.
  • Comparing two payloads: format both with sorted keys and the same indentation, then compare them with any diff tool; differences in key order no longer show up as noise.
  • Shrinking a payload: minify a fixture or a JSON value before embedding it in a URL parameter, an environment variable or a test file.
  • Checking IDs and amounts: if a payload contains integers above 9007199254740991, the tool warns you before you trust values that JavaScript would silently round.

How it works under the hood

The tool uses the browser's built-in JSON.parse and JSON.stringify functions, which implement the JSON standard strictly. Formatting means parsing the text into a data structure and serialising it again with the chosen indentation; minifying is the same operation with no indentation at all. Sorting keys rebuilds every object, at every level of nesting, with its keys in alphabetical order. Array order is never changed, because in JSON it is meaningful.

When parsing fails, the position reported by the browser is converted into a line and column number so you can jump straight to the problem. Because the formatter follows the standard, it rejects what other tools sometimes tolerate: comments, trailing commas, single-quoted strings, unquoted keys, NaN, Infinity or undefined.

JavaScript stores every number as a 64-bit floating-point value, which represents integers exactly only up to 9007199254740991 (Number.MAX_SAFE_INTEGER). A larger integer, such as a 64-bit database ID, would be rounded to the nearest representable value during parsing, so the formatted output could show a different number from your input. The tool detects such integers and warns you; the safe fix is to have them transmitted as strings, for example "id": "9007199254740993".

If an object contains the same key twice, standard JSON.parse keeps only the last value, and so does this formatter. The earlier value disappears from the output, which is worth knowing when a formatted document seems to have lost data.

Privacy: your JSON never leaves the browser

Parsing, formatting, validation and file reading all happen in your browser tab. Nothing you paste or open is uploaded, logged or stored on a server, and the Download button creates the file directly on your device. You can therefore format payloads that contain API tokens, customer records or internal configuration without exposing them to a third party. That said, it is still good practice to remove secrets from data you share with colleagues.

Limits and tips

  • Multi-megabyte documents are handled, but for a smooth experience keep inputs under roughly 10 MB; beyond that, formatting and display depend on your device's memory and speed.
  • The formatter accepts strict JSON only. JSON5, JSONC (JSON with comments) and JavaScript object literals must be cleaned up first: remove comments and trailing commas, and put keys and strings in double quotes.
  • Duplicate keys are not reported as errors: the last value wins, as in JSON.parse.
  • Large integers above 9007199254740991 trigger a warning and may be rounded in the output. Keep the original text if exact values matter.
  • Formatting normalises some notations: an escaped character such as \u00e9 may come back as é, and a number written as 1.0 or 1e2 is output as 1 or 100. The value is the same, but the text differs.

Frequently asked questions

Is my JSON sent to a server?

No. The tool runs entirely in your browser using the native JSON functions. Pasted text and opened files stay on your device and are not stored.

Why does the validator reject comments?

The JSON standard does not allow comments. Some editors and tools accept them in formats like JSONC or JSON5, but a strict parser, including the one in every browser, treats them as errors.

What is the difference between formatting and minifying?

Formatting adds line breaks and indentation so humans can read the structure. Minifying removes every unnecessary space and line break to make the text as small as possible. Both produce the same data.

Why did a large number change after formatting?

JavaScript can only represent integers exactly up to 9007199254740991. Larger integers are rounded when parsed. The tool warns you when this happens; store such values as strings to keep them intact.

What happens if a key appears twice in the same object?

Only the last value is kept, which is the standard behaviour of JSON.parse. The first occurrence will not appear in the formatted output.

Does sorting keys change my data?

No. Key order has no meaning in a JSON object, so sorting only changes how the document looks. Arrays keep their original order.

How big a file can I open?

Documents of several megabytes work well. Around 10 MB is the recommended limit for a responsive page; beyond that it depends on your device.

Which indentation should I choose?

Two spaces is the most common choice in JavaScript projects and keeps deep nesting compact. Four spaces is common in other ecosystems, and tabs let each reader set their own width. Use whatever your project already uses.