Skip to content
Case Converter Online
en

JSON Formatter and Validator

Paste JSON to pretty print it, minify it or check that it is valid. Errors show the exact line and column, and your data never leaves your browser.

Paste JSON or press Sample. Press Ctrl and Enter to format. Everything runs in your browser.

What a JSON formatter does

JSON (JavaScript Object Notation) is the most common format for sending data between programs. APIs usually return it as one long line with no spaces, because whitespace adds bytes and the computer does not need it. People do need it. A JSON formatter adds line breaks and indentation so you can see the structure: which values belong to which object, and where each array starts and ends.

This tool does three jobs:

  • Format turns compact JSON into readable, indented JSON.
  • Minify removes every space and line break that is not inside a string.
  • Validate checks the JSON against the standard and reports the first problem it finds.

How to use it

  1. Paste your JSON into the left box. It is formatted as soon as you paste. You can also press Open file to load a .json file, or Sample to try an example.
  2. Pick an Indent: 2 spaces, 4 spaces or Tabs.
  3. Press Format, Minify or Validate. Ctrl+Enter runs the last action from the keyboard.
  4. Turn on Sort keys A to Z if you want alphabetical keys.
  5. Press Copy, or Download to save the result as a .json file.

After the first run, the result updates as you type, so you can fix a problem and watch it clear.

Before and after

This is a typical API response with no whitespace:

{"id":42,"name":"Ada Lovelace","active":true,"roles":["admin","editor"],"address":{"city":"London","zip":"NW1"},"score":98.50,"manager":null}

After Format with 2 spaces:

{
  "id": 42,
  "name": "Ada Lovelace",
  "active": true,
  "roles": [
    "admin",
    "editor"
  ],
  "address": {
    "city": "London",
    "zip": "NW1"
  },
  "score": 98.50,
  "manager": null
}

Note that 98.50 stays 98.50. The formatter reads your text with its own parser and copies numbers character for character. A large ID such as 12345678901234567890 also stays exact, while a tool built on JSON.parse would print 12345678901234567000.

With Sort keys A to Z and 4 spaces, {"name":"Ada","age":36,"address":{"zip":"NW1","city":"London"}} becomes:

{
    "address": {
        "city": "London",
        "zip": "NW1"
    },
    "age": 36,
    "name": "Ada"
}

Validate gives a short summary for valid input. For the first example it reports: “Valid JSON. The root is an object with 12 values in total, nested 3 deep.”

Error messages you might see

When the JSON is broken, the message below the boxes gives the line and column, and Show in input jumps the cursor to that spot. These are real messages from the tool:

Mistake Message
Comma after the last item Line 4, column 1: Trailing comma before “}” is not allowed
Single quotes Line 1, column 2: Expected a property name in double quotes but found a single quote (JSON strings need double quotes)
Missing comma between items Line 3, column 3: Expected “,” or “}” after a value but found “””
Key without quotes Line 1, column 2: Expected a property name in double quotes but found “n”
A // comment Line 2, column 3: Comments are not allowed in JSON

These rules come from the JSON standard. JavaScript object literals allow single quotes, unquoted keys and trailing commas, which is why code copied from a .js file often fails here. If your data really is JavaScript, the JavaScript Formatter is the better fit.

Tips and limits

  • Strict JSON only. undefined, NaN, comments and trailing commas are reported as errors, because other programs will reject them too.
  • Duplicate keys are kept as written. The formatter does not merge or drop them.
  • Minify keeps the content of strings untouched, including spaces inside them.
  • To check a whole file, use Open file. Everything stays on your device.

Other ways to format JSON

VS Code. Open a .json file and run Format Document from the command palette. VS Code uses its built-in JSON formatter.

Command line with jq. jq . data.json prints formatted JSON, and jq -c . data.json prints it compact. jq also lets you filter and reshape data.

Command line with Python. python -m json.tool data.json formats a file with 4 spaces. It is part of the standard library, so it works wherever Python is installed.

In JavaScript. JSON.stringify(JSON.parse(text), null, 2) formats a string, but it goes through JavaScript numbers, so long IDs can lose digits.

To turn JSON into a config file, use the JSON to YAML Converter. To embed JSON inside another JSON string, use JSON Stringify Text. To build JSON from a spreadsheet export, try CSV to JSON.

JSON Formatter: questions and answers

Is my JSON sent to a server?

No. The formatter runs as JavaScript in your browser tab. Nothing you paste or open is uploaded, so it is safe to use with API responses, config files and other private data.

Why does the formatter say comments are not allowed?

Standard JSON has no comments. Files such as tsconfig.json or VS Code settings use a looser format often called JSONC, which allows them. Remove the comments, or keep the file in an editor that understands JSONC.

Will formatting change my numbers?

No. Many tools read numbers into JavaScript and print them back, which turns 98.50 into 98.5 and rounds very large IDs. This formatter copies every number exactly as you wrote it.

What does Sort keys A to Z do?

It puts the keys of every object in alphabetical order, at every level of nesting. Arrays keep their order. Sorting makes two versions of a file easier to compare in a diff.

Can I format a very large JSON file?

Yes. Use Open file to load it from your device. Files up to 20 MB are accepted, and the speed depends on your computer, since all the work happens locally.

More code and data tools

See all tools