JSON prettify and format

Format JSON instantly

Paste JSON, optionally sort keys, choose indentation, then copy output

Last updated: February 6, 2026
Frank Zhao - Creator
CreatorFrank Zhao
Sort keys :
Indent size :
Your formatted JSON will appear here

Introduction / overview

A JSON prettifier takes JSON input and outputs the same data with consistent whitespace, line breaks, and indentation. This makes it easier to read, review, and copy into tools.

Why this tool is safe

  • Formatting runs locally in your browser.
  • Invalid JSON is detected and flagged before output is produced.

If you want to transform formats instead of just formatting, try JSON to YAML or YAML to JSON.

How to use / quick start

1

Paste JSON

Paste JSON into the left box. The tool validates as you type.

2

Choose formatting options

Turn on Sort keys to make object key order stable, and select an indentation level.

3

Copy the output

Use the copy button on the right to copy the formatted JSON.

A quick mental model

Indentation controls how many spaces are added per nesting level. If your indent size is kk, a line at depth dd is indented by kdk\cdot d spaces.

indent(d)=kd\text{indent}(d)=k\cdot d

Step-by-step examples

Example 1: Basic formatting

Input:

{"b":2,"a":1}

Output (indent = 2, Sort keys on):

{
  "a": 1,
  "b": 2
}

Example 2: Nested objects

Sort keys applies at every object level, not just the top.

{"z":1,"obj":{"b":2,"a":1}}

Real-world examples / use cases

  • Make API responses readable during debugging.
  • Normalize JSON before pasting into documentation or tickets.
  • Sort keys to reduce noisy diffs in code reviews.

Common scenarios / when to use

Use Sort keys when you want stable, predictable output.

Key sorting is especially useful when your source JSON comes from systems that do not preserve object key order.

Tips & best practices

  • Use 2 spaces for compact output that is still readable.
  • Use 4 spaces if you want deeper nesting to stand out more clearly.
  • Minified output is useful for query strings or compact storage, but harder to review.

Calculation method / mapping

The tool parses your JSON into a JavaScript value, optionally sorts all object keys (deeply), then stringifies it with your chosen indentation.

Mapping

  • Arrays keep order; objects may be re-ordered when Sort keys is on.
  • Indent = 0 removes extra whitespace (minified JSON).

Related concepts / background

JSON is a text format defined by a strict grammar. Many tools accept JSON-like variants. If your snippet has comments or trailing commas, you may still be able to format it, but you should confirm what your target system accepts.

Frequently asked questions

Does sorting keys change my data?

It changes the textual order of object keys, but not the underlying key/value pairs.

Why is my JSON reported as invalid?

Common causes include missing quotes around keys, trailing commas in strict JSON, or unmatched braces.

Limitations / disclaimers

Formatting is not validation for business rules

This tool checks syntax. It does not verify schema rules (required fields, ranges, or types beyond basic JSON parsing).

External references / sources

JSON prettify and format | CalculatorVast