DevSwitch.net
Back to Tools
{ }

JSON Beautifier

Format and validate JSON data for better readability

Code Tools

Tip: Paste your minified or compact JSON and click Beautify to format it with proper indentation. The tool will also validate your JSON syntax.

Runs in your browser

Input JSON Data

Format JSON so you can read it

Paste JSON, open a .json file or drop it on the input window, and it is formatted as you type: one key per line, nested objects indented, with 2 spaces, 4 spaces or tabs. JSON beautifier and JSON formatter are two names for the same job, and this page does both.

Formatting starts by reading the JSON with the browser's strict parser, so it validates the syntax on the way. If something is wrong, the result window says where (line and column) and the cursor jumps to that spot in your input.

JSON formatter example

A one-line API response, formatted with the default 2-space indent:

response.json
{"order":{"id":"A-1042","paid":true,"total":59.9,"items":[{"sku":"MUG-01","qty":2},{"sku":"TEE-L","qty":1}],"note":null}}
formatted.json
{
  "order": {
    "id": "A-1042",
    "paid": true,
    "total": 59.9,
    "items": [
      {
        "sku": "MUG-01",
        "qty": 2
      },
      {
        "sku": "TEE-L",
        "qty": 1
      }
    ],
    "note": null
  }
}

Why your JSON is invalid

JSON is stricter than JavaScript. These five cause most of the errors the validator reports:

  • Error

    {"a": 1,}

    Fix

    No comma is allowed after the last item of an object or array. Delete it.

  • Error

    {'a': 'b'}

    Fix

    Strings and keys need double quotes. Single quotes are JavaScript, not JSON.

  • Error

    {a: 1}

    Fix

    Every key is a string in double quotes: {"a": 1}.

  • Error

    // note

    Fix

    JSON has no comments. Remove them, or keep the file as JSONC or JSON5 for the tool that reads it.

  • Error

    NaN, undefined

    Fix

    Not JSON values. Use null, a number or a string instead.

Syntax is only the first check. To test that valid JSON also has the right fields and types, write a schema: JSON Schema validation explains how.

Indent, sort keys and what stays the same

Options

  • Indent: 2 spaces (the default most style guides use), 4 spaces or one tab per level
  • Sort keys: every object's keys in alphabetical order, at every level, so two files can be compared line by line
  • Arrays keep their order either way

Worth knowing

  • Whole numbers above 9007199254740991 lose precision, as in any JavaScript parser: keep long IDs as strings
  • 1.0 is written as 1, and escapes like \u00e9 as the character itself
  • If a key appears twice in one object, the last value wins

Need it on one line again?

The JSON minifier removes every space and line break and shows how many bytes it saved.

JSON beautifier questions

None in practice: both add line breaks and indentation so JSON is readable, and both are also called pretty printing. The opposite is minifying.

Yes, for syntax. JSON that can't be parsed is not formatted; you get the error with its line and column instead.

Click Open file or drop the file on the input window. It is read in your browser; Download saves the formatted copy as a .json file.

Not here, but the converters can: JSON to CSV, JSON to YAML and JSON to XML.

No. Formatting runs in your browser.