Skip to content
Devtoolry

JSON Formatter

Format and beautify JSON with configurable indentation and optional key sorting. Errors are reported with exact line and column.

Runs in your browser · Nothing uploadedFree · No sign-up

Something not working, or missing a feature? Send feedback

About the JSON Formatter

API responses and config files often arrive as one long line of JSON. The JSON Formatter turns it into readable, consistently indented JSON and tells you exactly where the syntax breaks when it is invalid.

Everything runs in your browser, so your input is never uploaded to a server.

How to use the JSON Formatter

  1. Paste JSON into the input panel, open a .json file, load it from a URL with From URL, or load the sample.
  2. Choose 2 spaces, 4 spaces or tabs for indentation, and switch on key sorting if you want a stable order.
  3. Fix any error using the reported line and column, then copy or download the formatted result, or switch the output to Tree to fold and explore it.

Example

Pretty print a minified API response

Input

{"id":42,"name":"Ada","roles":["admin","dev"],"active":true}

Result

{
  "id": 42,
  "name": "Ada",
  "roles": [
    "admin",
    "dev"
  ],
  "active": true
}

Formatted with 2-space indentation. Switch on Sort keys to order "active", "id", "name", "roles" alphabetically.

Common mistakes

  • Trailing commas. A comma after the last item, as in [1, 2, ], is valid JavaScript but invalid JSON. Remove it; the error points to the character right after it.
  • Single quotes and unquoted keys. JSON requires double quotes around every key and string: {"name": "Ada"}, not {name: 'Ada'}. Objects copied from JavaScript code often break this rule.
  • Comments. Standard JSON has no comments. Files such as tsconfig.json accept them (JSONC), but APIs and JSON.parse do not, so strip // and /* */ comments first.
  • Very large numbers. Integers above 9,007,199,254,740,991 cannot be represented exactly in JavaScript, so 12345678901234567890 is formatted as 12345678901234567000. Send large IDs as strings.
  • Duplicate keys. When a key appears twice in an object, only the last value is kept. Search the input for the key if a value seems to have disappeared.

Works well with the JSON Formatter

  • JSON Validator: check whether JSON is valid without changing its layout.
  • JSON Viewer: explore a large document as a collapsible tree and copy paths.
  • JSON Diff: compare two versions of a response, ignoring key order.
  • JSON to TypeScript: turn the formatted response into TypeScript interfaces.
  • JSON Minifier: compress it back to a single line before sending.

Frequently asked questions

Does sorting keys change my data?

No. Only the order of object keys changes; values and array order stay exactly as they were. Sorted keys make two documents easier to compare.

Why is my JSON invalid?

The most common causes are trailing commas, single quotes instead of double quotes, unquoted keys and comments, none of which are allowed in standard JSON. The error message points to the first problem.

Are large numbers like 64-bit IDs kept exactly?

Yes, in current browsers. JavaScript numbers lose precision above 2^53, so JSON.parse turns 12345678901234567891 into 12345678901234567000. The formatter keeps the original digits of such integers and tells you how many it found.

Can I load JSON from an API URL?

Yes. From URL downloads the file in your browser, without cookies, and never through our server. The server must allow cross-origin reads (CORS), as most public APIs and raw GitHub files do; otherwise save the file and open it.

Is my JSON uploaded anywhere?

No. Parsing and formatting happen in your browser with the built-in JSON parser, so the data never leaves your device.

What is the difference between formatting and validating?

Both parse the input and report the first syntax error with its line and column. Formatting also rewrites the layout; validation leaves your text unchanged.

Can I format JSON Lines (NDJSON)?

Not as one document: each line of JSON Lines is a separate value. Format one line at a time, or wrap the lines in [ ] and separate them with commas.

Guides and tutorials