toooly-box

JSON Formatter

Paste JSON on the left and get a readable, indented version. The file never leaves your device.

runs locally
JSON formatter
Paste your JSON
Result

What is a JSON formatter?

A JSON formatter takes JSON written on one line and prints it with indentation and line breaks, so the structure becomes visible. It changes only the whitespace: the data, the key order and the values come out identical. Most formatters also report the first syntax error if the text will not parse.

How it works

The formatter parses your input with the browser’s own JSON parser, then prints it back with the indentation you pick. Parsing is what makes it trustworthy: if the text comes back formatted, it was valid JSON.

A syntax error is reported with the position where the parser gave up, which is usually a trailing comma, a single quote, or an unquoted key.

Sorting keys alphabetically is useful before a diff: two API responses that carry the same data in a different key order produce an empty diff once both are sorted.

What a JSON formatter actually does

JSON arrives from an API as one unbroken line. A JSON formatter, also called a JSON beautifier or JSON pretty printer, parses that line into the structure it describes and prints it back with one key per line and a level of indentation per level of nesting. Nothing about the data changes: the same objects, arrays, strings and numbers come back, only laid out so a person can follow them.

The parse is the part that matters. To indent your text the formatter has to understand it first, so a result that comes back formatted is a result that was valid JSON. That is why a JSON formatter and a JSON validator are the same check seen from two sides, and why you can paste an API response here to answer the question "is this even valid?" before you go looking for a bug in your own code.

How to format JSON online, step by step

  • Paste or open the file paste the response into the left pane, or load a .json file from disk with Open file. Large responses are fine; the work happens on your machine, so there is no upload wait and no size limit beyond your own memory.
  • Pick the indentation two spaces is the default and the most common convention in JavaScript and TypeScript projects; four spaces suits Python and Java codebases; tab suits Go. Minify strips every optional space instead, for when you need the smallest possible payload.
  • Sort the keys if you are about to diff two API responses carrying the same data in a different key order produce a noisy diff. Sort both and the diff collapses to the fields that genuinely changed.
  • Take the result Copy puts the formatted JSON on the clipboard; Download saves it as a .json file you can commit, attach to a ticket or feed to another tool.

Reading a JSON syntax error

When the parse fails, the error names the position where the parser gave up: not necessarily where the mistake is, but always after it. Four causes account for most of them.

  • A trailing comma JavaScript object literals allow a comma after the last property; JSON does not. This is the single most common invalid-JSON error, and it usually comes from hand-editing a config file.
  • Single quotes JSON strings use double quotes only. 'name' is a syntax error, "name" is a string.
  • An unquoted key {name: "x"} is valid JavaScript and invalid JSON. Every key must be a quoted string.
  • A stray newline or control character inside a string a real line break inside quotes must be written as \n. Copying a multi-line value out of a terminal is the usual source.

When you want a different tool

A formatter is for reading and checking. If you need to pull one field out of a large document, a JSONPath or jq expression is the right instrument. If you need to compare two responses field by field, use a JSON diff after sorting both here. If what you have is a JWT, the payload is Base64url inside the token rather than plain JSON: decode it first. And if your file is NDJSON, one JSON document per line, format the lines one at a time: the whole file is deliberately not a single valid JSON document.

Questions people ask

Is my JSON uploaded anywhere?

No. The parsing and formatting happen in your browser with JavaScript. Nothing is sent to a server, so you can paste internal API responses safely.

What is the difference between a JSON formatter and a JSON validator?

They are the same check seen from two sides. The formatter has to parse your input to indent it, so invalid JSON produces an error instead of output. Use the validator when you only want the verdict and the error position.

Why does my JSON fail with a trailing comma?

JSON does not allow a comma after the last element of an object or array, even though JavaScript does. Remove it and the text will parse.