Free online tools
English EN, Choose a language

JSON formatter

Paste JSON to format it with 2 or 4 spaces or tabs, minify it, sort the keys, and see the exact line of any error.

Action

Indent

Result

Paste JSON and the formatted result appears here.

Runs in your browser. Your JSON is never uploaded or stored.

How to format JSON online

  1. Paste your JSON into the box, or press Insert example. The result appears as you type.
  2. Choose Format to pretty-print or Minify to remove all spaces. For formatting, pick 2 spaces, 4 spaces or a tab.
  3. Tick Sort keys alphabetically to order every object's keys, at every depth. Arrays keep their order.
  4. Copy the result, download it as a .json file, or press Use as input to keep working on it.

The page validates while it formats: if the text is not valid JSON you get the line, the column and a caret under the problem instead of a result.

Format and minify: one example

Compact JSON as it arrives from an API:

{"name":"Ada Lovelace","born":1815,"tags":["math","code"],"address":{"city":"London","geo":{"lat":51.5,"lng":-0.12}},"active":true,"spouse":null}

Formatted with 2 spaces:

{
  "name": "Ada Lovelace",
  "born": 1815,
  "tags": [
    "math",
    "code"
  ],
  "address": {
    "city": "London",
    "geo": {
      "lat": 51.5,
      "lng": -0.12
    }
  },
  "active": true,
  "spouse": null
}

Minified, the same data on one line again, with the saving shown in the stats under the result:

{"name":"Ada Lovelace","born":1815,"tags":["math","code"],"address":{"city":"London","geo":{"lat":51.5,"lng":-0.12}},"active":true,"spouse":null}

Sorting keys is useful for comparing two files or committing config to version control, because the same data always produces the same text.

{"b":2,"a":{"z":1,"y":[3,1]}}
becomes
{
  "a": {
    "y": [
      3,
      1
    ],
    "z": 1
  },
  "b": 2
}

Fixing JSON errors

Most invalid JSON comes from a handful of mistakes, usually from copying a JavaScript object literal or a config file. Take this input:

{
  "name": "Ada",
  "tags": ["math", "code",],
  "born": 1815
}

The tool reports: Invalid JSON at line 3, column 27: Trailing comma: remove the comma before ']'. with the position marked:

Line 3, column 27
  "tags": ["math", "code",],
                          ^

The common causes and their fixes:

The exact wording of the message comes from your browser's JSON parser and differs a little between Chrome, Firefox and Safari; the line, column and hint are worked out by this tool.

What JSON allows

TypeExampleNotes
Object{"a": 1}Keys must be double-quoted strings; the order is kept as written
Array[1, "two", null]Any mix of types, no trailing comma
String"caf\u00e9"Double quotes only; escape ", \ and control characters
Number-12.5e3No leading +, no leading zeros, no hex, no NaN
Boolean, nulltrue false nullLower case only

The format is defined by RFC 8259 and ECMA-404. Big integers are the one trap: JavaScript reads numbers as 64-bit floats, so an id such as 12345678901234567890 silently changes to 12345678901234567000.

{"id": 12345678901234567890}
The tool warns when it sees a number with more than 15 digits; send such ids as strings.

Formatting JSON safely

JSON from an API often contains tokens, emails or customer data. This page parses and prints it in your browser and makes no network request with it, so pasting a production response is safe from the tool's side. Close the tab or press Clear when you are done, as your browser may keep text in the box until then.

To validate against a schema, or to check a file with comments (JSONC, used by many editors), you need a different tool; this one follows strict JSON. To turn a list of objects into a spreadsheet use JSON to CSV, and to read a JSON Web Token use the JWT decoder.

Related tools

JSON formatter FAQ

How do I format JSON?

Paste the JSON into the box and keep Format selected. The pretty-printed result appears at once; choose 2 spaces, 4 spaces or a tab, then copy or download it.

How do I minify JSON?

Choose Minify. All spaces and line breaks outside strings are removed and the stats show how many bytes you saved.

Why does it say my JSON is invalid?

The message gives the line and column. The usual causes are a trailing comma, single quotes, unquoted keys, comments or undefined/NaN values, and the tool names the likely one.

Does formatting change my data?

No, except for two things you control: sorting keys reorders them, and very large integers lose precision when read (the tool warns you). Everything else keeps its value.

Is my JSON uploaded anywhere?

No. It is parsed and printed in your browser and nothing is sent or stored.

Can it format JSON with comments?

No. Strict JSON has no comments. Remove them first, or use an editor that supports JSONC.

Is there a size limit?

There is no fixed limit. Several megabytes work, and the output box shows the first 250,000 characters while Copy and Download use the full result.

Missing something in the JSON formatter?Suggest an idea. It takes 20 seconds and we read every one.Suggest an idea

Sends only what you type here, never the text you work with. Your email is used only to reply about this idea.

Free online tools