webtools

JSON Formatter and Validator

Private: nothing leaves your browser

Result
output

                  

Waiting for JSON

Paste any JSON to pretty print it with proper indentation, or minify it back to a single line. If it will not parse, you get the exact line and column that broke, and it all happens on your own device.

About this JSON formatter

Badly wrapped JSON is hard to read and harder to debug, and most online formatters make you upload your payload to somebody else's server before they will help. This one is plain JavaScript running on this page, so API responses, config files and anything with a token in it stay on your own machine. Nothing is uploaded, logged or stored, and the page keeps working with your connection switched off.

Formatting changes whitespace, and nothing else except numbers: key order, strings and booleans come back out exactly as they went in. Numbers are read and written again, so a very long integer loses its last digits, which matters if your JSON carries IDs rather than quantities. When JSON will not parse, the status line names the problem and the line and column to look at, which is usually a trailing comma, a single quote or a stray comment. If what you want is a version you can comment and edit by hand, the same paste goes through the JSON to YAML converter.

Two things a formatter cannot fix, and both look like bugs in the formatter. Large integers lose precision, because JavaScript parses every number as a 64 bit float: an ID written as 9007199254740993 comes back as 9007199254740992, and anything above 253 is at risk. IDs that large should be sent as strings, and this page is where you find out that yours are not. Duplicate keys are the other one: two "id" keys in the same object is legal JSON, but only the last survives parsing, so one of them disappears without a warning from any parser. Both are properties of JSON itself rather than of this page, and both are worth knowing before you paste a payload into a bug report.

How to format and validate JSON

  1. Paste your JSON into the left box, or drag a .json file onto it.
  2. Pick Format for readable output or Minify for the smallest single line.
  3. Choose the indent you prefer: two spaces, four spaces or a tab.
  4. Check the status line. If something is wrong it names the line and column to fix.
  5. Press Copy to put the result on your clipboard.

Common questions about JSON formatting

Is it safe to paste an API response with real data in it?

No. The formatter is plain JavaScript running on this page, so your JSON is parsed on your own device and never sent anywhere. You can open the tool, turn off your internet connection, and it still works.

Is this a JSON viewer, a beautifier or a validator?

All three, because they are the same job under different names. Pretty printing the JSON is what makes it readable, which is what people mean by a viewer or a beautifier, and parsing it in order to do that is what validates it. Format gives you the readable version, Minify gives you the smallest one, and if it will not parse you get the line and column to fix.

Why is my JSON invalid when it looks correct?

The usual causes are a trailing comma after the last item, single quotes instead of double quotes, comments, unquoted keys, or values like NaN and undefined. Strict JSON allows none of those. The status line points at the exact line and column so you can find it fast.

Does formatting change my data?

Whitespace changes, and so can a number. Key order, strings and booleans come back exactly as they went in. Numbers are parsed and written out again, so 1e3 becomes 1000, 1.0 becomes 1, and an integer longer than about sixteen digits loses its last digits because that is the limit of what JavaScript can hold. Duplicate keys are the other loss: two keys of the same name in one object are legal JSON, but only the last survives parsing, here and in every other parser, so the document comes back one key shorter. If your JSON carries large IDs, keep them as strings.

How large a file can it handle?

Files of a few megabytes format in well under a second on a normal laptop or phone. The only real limit is your browser's memory, since the whole document is parsed at once.

Next

Related tools

All Dev tools