JSON Formatter

Pretty-prints JSON with 2-space, 4-space or tab indentation and an optional recursive key sort, keeping big integers like 12345678901234567890 exact. Formatting is done client-side.

Last updated:

Paste your JSON here...
Loading editor...
Loading editor...

JSON Formatter & Beautifier — Pretty Print JSON Online

What JSON Formatter does

JSON Formatter adds line breaks and a selected indent to valid JSON so nested objects are easier to inspect. Choose two spaces, four spaces, or one tab, and optionally sort object keys. It preserves numeric literals in its formatted text, including integers beyond JavaScript’s safe integer range. Use it when reviewing a response or configuration file; it does not enforce an application schema.

Worked examples

Read an invoice identifier without rounding it

An API response is compressed into one line and contains an identifier too large for a JavaScript Number to represent exactly. Format the text with the default two-space indent.

Input

{"id":12345678901234567890,"label":"invoice"}

Output

{
  "id": 12345678901234567890,
  "label": "invoice"
}

The formatter adds a line for each property and leaves the 20-digit token exactly as it appeared in the source. That behavior is specific to this tool’s token-preserving formatting path. If application code later reads the same JSON with ordinary JSON.parse, the integer may be rounded before your code sees it. Treat large numeric identifiers as strings in an API contract, or use a parser designed to preserve integer tokens, when exact arithmetic or identity matters.

Sort nested keys and indent with tabs

A configuration file is hard to compare because properties arrived in different orders. Select “1 tab” and enable “Sort keys” before pasting the document.

Input

{"z":1,"a":{"y":2,"x":3}}

Output

{
	"a": {
		"x": 3,
		"y": 2
	},
	"z": 1
}

The output contains actual tab characters, not one space per indentation level. Sorting applies inside the nested object as well as at the root: a moves before z, and x moves before y. Array order is not sorted by this option, because changing array positions would change the data. The choice is useful for a stable review copy, but preserve the original file if another system relies on its existing text or signature.

What to check before using the output

Valid syntax is different from a valid contract

The formatter needs parseable JSON and reports a syntax error when the grammar is broken. It cannot decide whether an invoice must include currency, whether a number is in range, or whether an email has the expected shape. Use JSON Schema Validator with the appropriate schema for those rules. A clean, indented output only shows that the text could be formatted.

A later parse can lose integer precision

The rendered text keeps the original numeric literal, but JavaScript Number is exact only for integers up to 2^53 − 1. JSON.parse of 9007199254740993 yields a rounded Number. Copying this tool’s output into a program that performs a normal parse does not preserve that identifier automatically. Decide whether your contract should encode the value as a string or use a BigInt-aware parser before doing calculations or equality checks.

Input token: 9007199254740993
JSON.parse result in JavaScript: 9007199254740992

Key sorting changes the exact bytes

JSON objects are often treated as unordered data, but a signature, checksum, source diff, or cache key may operate on the literal bytes. Enabling Sort keys changes the serialized order and therefore may change those byte-based results. Keep sorting off when you need to preserve an existing signed document. When you do sort for a review, make the choice explicit to the person consuming the copy.

Formatting does not turn JSONC into JSON

Comments, single-quoted strings, and trailing commas are accepted by some configuration formats but are not valid JSON. This formatter parses standard JSON; it does not silently strip extensions to make them pass. If the source is JSONC, decide whether to remove comments in a separate documented step. Otherwise, the output would no longer represent the same source text reviewers saw.

How to Use the Tool

  1. Paste compressed or unreadable JSON into the input editor on the left side.
  2. Select your preferred indentation style (2 spaces, 4 spaces, or tab character) from the toolbar.
  3. The formatted output appears immediately in the right editor with proper indentation and line breaks.
  4. Use the Copy button to send the prettified JSON to your clipboard, or Download to save as a .json file.
  5. For compact JSON, open the separate JSON Minifier tool.

Key Features & Specifications

  • Configurable indentation: 2-space, 4-space, or tab-based formatting
  • Preserves all original data values including Unicode, escaped characters, and large numbers
  • Syntax-highlighted output editor makes structural review immediate
  • Download formatted output as a properly named .json file

Frequently Asked Questions (FAQ)

Q:Does the formatter preserve an integer beyond the safe Number range?
It preserves the numeric token in the formatted text. Ordinary JSON.parse in your own JavaScript program can still round that value, so choose a suitable representation or parser for exact use.
Q:What exactly does Sort keys reorder?
It sorts keys in objects, including nested objects. It does not reorder array elements. Sorting changes the exact text and can change signatures or hashes over that text.
Q:Is the “1 tab” choice a literal tab?
Yes. The formatter passes a tab indentation string to its JSON formatting function; the output contains tab characters at each nesting level.
Q:Why does a JSON file with comments fail?
Comments are outside standard JSON grammar. The formatter does not treat the input as JSONC, so remove comments or use a tool intended for that format.