Ontoom

JSON formatter

Beautify, minify and validate JSON in the browser.

Important: Your JSON never leaves the browser.

What this tool does

Paste some text and the formatter runs it through the same parser your browser uses (JSON.parse). You get one of three results: pretty-printed JSON with the indent you chose, minified JSON on a single line, or confirmation that the input is valid. When parsing fails, the parser's error is shown, usually with the character position where it broke.

Everything happens in your browser. The JSON is not sent to Ontoom's servers, which matters when it is a response from an internal API or a config file. Even so, avoid pasting production tokens or passwords into any website, this one included.

How to use it

  1. Paste your JSON into the input box. Objects, arrays and bare values such as a quoted string all work.
  2. Choose an indent (2 or 4 spaces are the usual choices) and click Format.
  3. Click Minify when you need one line, for example for an environment variable or a curl body.
  4. Click Validate when you only want to know whether the text parses.
  5. Copy the result with the Copy button.

The rules that trip people up

JSON is defined by RFC 8259 and ECMA-404. It looks like JavaScript but is much stricter. Most errors come from one of these:

  • Keys and strings need double quotes. {'name': 'Ana'} with single quotes is invalid.
  • No trailing commas: [1, 2, 3,] and {"a": 1,} both fail.
  • Comments are not part of JSON. Files like tsconfig.json allow them because they use a dialect (JSONC), not plain JSON.
  • The only literals are true, false and null, in lowercase. undefined, NaN and Infinity do not exist in JSON.
  • Numbers cannot have leading zeros (007) or a plus sign (+5).
  • Newlines and tabs inside strings must be escaped as \n and \t.

Example

Minified input, as an API usually returns it, and the 2-space output:

{"id":42,"active":true,"tags":["qa","api"],"owner":{"name":"Test","email":null}}

{
  "id": 42,
  "active": true,
  "tags": [
    "qa",
    "api"
  ],
  "owner": {
    "name": "Test",
    "email": null
  }
}

Things worth knowing

Formatting only changes whitespace, but JSON.parse has two side effects that can surprise you. If an object repeats a key, only the last value survives. And integers above 9,007,199,254,740,991 (2^53 − 1) lose precision because JavaScript stores them as floating-point numbers. That is why long IDs, like those from some databases and social networks, should travel as strings.

Key order is preserved as it came in. To compare two documents, format both with the same indent before running a diff.

Everyday uses

  • Reading an API response during manual testing, or after running a request with cURL online.
  • Inspecting a token: the JWT decoder shows the header and payload, which are JSON.
  • Minifying a fixture before storing it in a variable or database column.
  • Finding the stray comma or quote that breaks a config file.

Frequently asked questions

Is my JSON uploaded anywhere?
No. Formatting and validation use your own browser's JSON.parse. The text does not leave your device.
Why does JSON with comments fail?
Comments are not part of the JSON spec. Remove the // or /* */ lines, or use a tool built for JSONC or JSON5.
What is the difference between format and minify?
Formatting adds line breaks and indentation for readability. Minifying removes every non-essential space, giving the smallest text with the same data.
Why did a large number change after formatting?
Integers above 2^53 − 1 cannot be represented exactly as JavaScript numbers. Ask the source system to send that field as a string.
Does the tool fix my JSON automatically?
No. It shows the parser error so you can fix it yourself. Automatic fixes could change your data without you noticing.

Written by Orlando Alves · reviewed on · Editorial policy

See also