JSON Formatter & Beautifier

This JSON formatter turns minified or messy JSON into clean, indented text you can read, and squeezes it back to one line when you need it small. Paste your data, pick an indent, and the pretty printed result appears as you type, with any syntax error pinned to its exact line and column.

Output
Indent
Valid JSON · 148 characters in, 205 out

Runs entirely in your browser. Nothing you paste is uploaded or stored.

How do you format JSON?

Paste the JSON into the formatter and it is parsed, then printed again with one key or array item per line, indented by the number of spaces you choose. If the text is not valid JSON you get the line, column and a likely fix instead of output. Minify does the reverse and removes every space and line break that is not inside a string.

How to use the JSON beautifier

This JSON formatter online works entirely in the page: nothing is uploaded, and the result updates as you type or edit the input.

  1. Paste JSON into the left box, drop a .json file on it, or use Open file. The file is read by your browser and is never uploaded.
  2. Choose Beautify for pretty JSON or Minify to strip whitespace for a smaller payload.
  3. Pick 2 spaces, 4 spaces or tabs, and tick Sort keys if you want object keys in alphabetical order (handy before comparing two documents).
  4. Copy or download the result. If there is an error, press Go to error to jump to the problem character.

JSON pretty print, without changing your data

A formatter that simply runs your text through JSON.parse and back will quietly round large integers (anything above 253, such as 64-bit IDs) and rewrites numbers like 1.50 as 1.5. This beautifier uses its own JSON parser, which keeps every number and string exactly as you wrote it and only changes the whitespace between tokens, so the output holds exactly the same data. Duplicate keys are kept too, and flagged, because most parsers silently keep only the last one.

Before and after, using 2-space indentation:

{"id":7,"tags":["a","b"],"owner":{"name":"Sam"}}
{
  "id": 7,
  "tags": [
    "a",
    "b"
  ],
  "owner": {
    "name": "Sam"
  }
}

JSON formatter and validator in one

Formatting only works on valid JSON, so the formatter validates first against the grammar in RFC 8259. The rules people trip over most are:

  • Keys and strings need double quotes; single quotes are not JSON.
  • No comma after the last item in an object or array.
  • No comments, and no undefined, NaN or Infinity.
  • Numbers cannot have leading zeros (007) or a leading +.
  • Line breaks and tabs inside strings must be escaped as \n and \t.

For a fuller error report with hints for each of these, use the JSON validator. To explore a big document instead of reading it top to bottom, open it in the JSON viewer.

Format JSON in code

When you need clean JSON inside a script or pipeline rather than in a browser, every major language has a one-liner:

// JavaScript / Node.js
JSON.stringify(data, null, 2)

# Python
python -m json.tool input.json

# Command line with jq
jq . input.json

Two spaces is the most common indent in JavaScript projects, four in Python. Neither is more correct: whitespace between tokens has no meaning in JSON, so pick whatever your team's formatter uses.

Frequently asked questions

What is JSON?

JSON is a lightweight, text-based format for exchanging structured data, built from objects (key–value pairs in braces), arrays (lists in square brackets), strings, numbers, true, false and null. It is defined by RFC 8259 and ECMA-404, and almost every programming language and web API can read and write it.

What is a JSON file?

A JSON file is a plain text file, usually ending in .json, whose entire content is one JSON value, typically an object or an array. Config files such as package.json, API responses saved to disk and data exports are common examples, and any text editor can open them.

What does JSON stand for?

JSON stands for JavaScript Object Notation. The name comes from its syntax, which is a subset of JavaScript object and array literals, but the format itself is language-independent.

What is JSON format?

JSON format means data written with the JSON syntax rules: keys and strings in double quotes, a colon between each key and value, commas between items, and nothing after the last item. Whitespace between tokens is optional, which is why the same data can be minified to one line or pretty printed with indentation.

How to format JSON?

To format JSON, paste it into the JSON formatter above and choose an indent of 2 spaces, 4 spaces or tabs; the beautified result appears instantly and can be copied or downloaded. In code you can do the same with JSON.stringify(value, null, 2) in JavaScript or python -m json.tool file.json on the command line.