About JSON Formatter

JSON (JavaScript Object Notation, standardized in RFC 8259 and ECMA-404) is the dominant data format for web APIs, configuration files, and log pipelines. Machines are happy to read it in a single line, but humans are not: a 40 KB API response collapsed into one line is effectively unreadable. A JSON formatter (also called a beautifier or pretty-printer) re-indents the structure so that every object key, array element, and nesting level sits on its own line.

This formatter runs entirely in your browser. Your JSON is never uploaded to a server, which matters when you are inspecting API responses that contain access tokens, customer records, or internal identifiers. It handles inputs up to 10 MB and uses a Web Worker for large payloads, so the page stays responsive while formatting.

How to use JSON Formatter

  1. Paste or type your JSON in the input area.
  2. Click "Format" or press Ctrl+Enter to beautify with consistent indentation.
  3. Copy the formatted output or download it as a file.

Example

Input

{"name":"DevToolKit","tools":["JSON","Encoding"],"active":true}

Output

{
  "name": "DevToolKit",
  "tools": ["JSON", "Encoding"],
  "active": true
}

How JSON formatting actually works

Formatting is a parse-and-reprint operation, not a text transformation. The tool first parses your input with a strict JSON parser — the same grammar your API client or backend uses. Parsing produces an in-memory tree of objects, arrays, strings, numbers, booleans, and nulls. The printer then walks that tree and writes it back out with consistent indentation (two spaces per level here).

Because the output is regenerated from the parsed tree, formatting is guaranteed not to change your data: key order, string contents, and number values survive untouched. The only thing that changes is insignificant whitespace, which the JSON grammar explicitly allows between tokens. This is also why a formatter doubles as a validator — if your input cannot be parsed, it cannot be formatted, and you get an error with a line and column instead.

What JSON does not allow (and where most invalid JSON comes from)

Most "invalid JSON" is actually valid JavaScript that people paste from code. The JSON grammar is far stricter than a JS object literal:

  • Keys must be double-quoted: {name: "a"} is a JS literal, not JSON. Write {"name": "a"}.
  • Single quotes are not allowed for strings — only double quotes.
  • Trailing commas are forbidden: [1, 2, 3,] fails to parse.
  • Comments (// or /* */) are not part of JSON. Config formats like JSONC and JSON5 allow them, but a strict parser will reject them.
  • NaN, Infinity, and undefined are not JSON values. APIs typically serialize these as null or strings.
  • Numbers cannot have leading zeros (01) or a bare leading dot (.5).

Practical uses

The most common workflow is debugging API responses: copy a response from curl, a network tab, or a log line, format it, and scan the structure. Formatted JSON also produces meaningful diffs in code review — one key per line means a change shows up as a one-line diff instead of a wall of text. When editing configuration by hand (package.json, tsconfig.json, CI files), formatting after each edit catches missing commas immediately, when the mistake is still easy to spot.

Common errors and how to fix them

Unexpected token '}' — or an error pointing at a closing bracket

Cause: Almost always a trailing comma before the } or ], e.g. {"a": 1,}.

Fix: Remove the comma after the last property or array element.

Unexpected token ''' (single quote)

Cause: The input uses single-quoted strings, which are valid in JavaScript and Python but not in JSON.

Fix: Replace single quotes with double quotes. If the data came from Python, use json.dumps() instead of str() on a dict.

Unexpected token 'N' / 'u' / 'I'

Cause: The input contains NaN, undefined, or Infinity — JavaScript values with no JSON representation.

Fix: Replace them with null, a number, or a quoted string before parsing.

Unexpected end of JSON input

Cause: The input was truncated — typically a log line that was cut off, or a partial copy of a large response.

Fix: Re-copy the complete payload. Check whether your logger truncates long lines (many default to 8–16 KB).

Bad control character in string literal

Cause: A raw newline or tab inside a string value. JSON strings must escape control characters as \n, \t, etc.

Fix: Escape the control characters, or find where the producer wrote raw bytes into the string.

Tips and best practices

  • Formatting preserves key order, but JSON itself does not guarantee it — never write code that depends on the order of object keys.
  • Very large numbers (above 2^53 - 1, like many 64-bit database IDs) lose precision when parsed as JavaScript numbers. If you see IDs ending in 000 after formatting, the producer should send them as strings.
  • Duplicate keys are technically parseable ({"a":1,"a":2}) but almost every parser silently keeps only the last value — treat duplicates in your data as a bug.
  • Use Ctrl+Enter (Cmd+Enter on Mac) to format without reaching for the mouse.
  • For committing to a repo, prefer 2-space indentation — it is the de-facto standard for package.json and most tooling output.

Frequently asked questions

Does formatting change my data?
No. The formatter parses your JSON into a tree and reprints it. Values, strings, key order, and structure are unchanged — only insignificant whitespace differs. If the input cannot be parsed, you get an error instead of silently altered output.
Is my JSON uploaded anywhere?
No. Parsing and formatting run in your browser via JavaScript (in a Web Worker for large inputs). The data never leaves your machine, so it is safe to format payloads containing tokens or personal data.
What is the maximum input size?
10 MB. Inputs of this size are processed in a background Web Worker so the page does not freeze.
Why do my 64-bit IDs look wrong after formatting?
JavaScript numbers are IEEE-754 doubles with 53 bits of integer precision. IDs larger than 9,007,199,254,740,991 get rounded during parsing. The correct fix is on the producing side: serialize large IDs as strings.
Can it format JSON with comments (JSONC)?
No — comments are not part of the JSON standard and the strict parser rejects them. Strip // and /* */ comments first, or keep JSONC files in tools that support them (like VS Code settings).
What indentation does it use?
Two spaces per nesting level, the convention used by npm, Prettier's JSON defaults, and most modern tooling.

Embed this tool

Add JSON Formatter to your own site, blog post, or internal docs — free, no signup. The widget runs entirely in your visitors' browsers, same as it does here.