JSON Formatter & Validator

Paste JSON to check that it is valid, then pretty-print it with the indentation you like or minify it to a single line. If something is wrong, you get the line and column of the first error.

Your JSON is parsed inside your browser and is never sent to our server.

How to use the JSON Formatter

  1. Paste your JSON into the input box, for example an API response, a config file or a log entry.
  2. Pick an indentation (2 spaces, 4 spaces or tabs) and tick Sort object keys if you want keys in alphabetical order.
  3. Press Format to pretty-print, Minify to strip all optional whitespace, or Validate only to just check it.
  4. If the JSON is invalid, read the message: it gives the line and column of the first problem and shows that line with a caret under the spot. Fix it and press the button again.
  5. Copy the result or download it as a .json file.

What counts as valid JSON

This tool checks your input against the JSON standard, RFC 8259, rather than the more forgiving rules of JavaScript. The mistakes it most often catches are:

Only the first error is reported, because one mistake (such as a missing quote) often makes everything after it look broken too. Line and column numbers start at 1, and the column counts characters on that line, with a tab counting as one.

What the formatter preserves, and what it changes

A formatter that simply runs your text through JavaScript's JSON.parse and JSON.stringify quietly rounds large integers, such as 64-bit IDs, and moves keys that look like numbers ("1", "2") to the front of each object. This tool uses its own parser instead, so numbers are copied exactly as written and keys stay in their original order unless you ask for sorting. Duplicate keys are kept and flagged, since the standard says names in an object should be unique and different programs handle duplicates differently.

Two things are normalized. Escape sequences in strings are rewritten in their shortest standard form, so "é" becomes "é" and "\/" becomes "/"; the text means the same thing. And whitespace outside strings is replaced by the indentation you chose. Objects nested more than 1,000 levels deep are rejected.

Frequently asked questions

Is my JSON sent to a server?

No. Parsing and formatting are done by JavaScript in your browser. That makes it safe for API responses containing tokens or personal data, although it is always good practice to remove secrets before sharing a file with anyone.

Why is the error position different from what my code editor says?

Editors and parsers sometimes point at the place where they noticed a problem rather than its cause. This tool reports the character where the text stops being valid JSON, for example the trailing comma or the single quote. If a string was never closed, it points to the opening quote.

Does sorting keys change my data?

Not its meaning: JSON objects are unordered collections, so sorted output describes the same data. Arrays are never reordered, because their order does matter. Sorting is by character code, so uppercase letters come before lowercase ones.

How big a file can it handle?

It depends on your device's memory. Files of a few megabytes format quickly on a typical computer; very large files may make the tab slow, especially on phones.

Will it fix my JSON automatically?

No. It tells you exactly where the problem is and what kind of problem it is, but it does not guess at a correction, because a wrong guess could silently change your data.

Sources: RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format

Related tools