JSON Formatter & Validator

Paste JSON to format, validate syntax, and explore structure with an interactive tree view.

Input
0 chars0 bytes
Output
{ }
output will appear here

How to format JSON online

  1. 01

    Paste your JSON

    Drop raw, minified, or malformed JSON into the left panel. You can also click paste to pull directly from your clipboard.

  2. 02

    Format or validate

    Click format to instantly beautify the JSON with consistent indentation. Syntax errors are flagged inline with the exact line and column.

  3. 03

    Inspect and copy

    Switch to tree view to navigate nested objects and arrays. Copy the formatted output or adjust indent size and key sorting in the settings panel.

Features

Instant validation

Real-time syntax checking catches missing commas, unquoted keys, trailing commas, and type mismatches as you type.

Syntax highlighting

Keys, strings, numbers, booleans, and null values are colour-coded so the structure is readable at a glance.

Interactive tree view

Collapse and expand any node. Useful for exploring deeply nested API responses without losing context.

Key sorting

Alphabetically sort all object keys at every depth level — useful for diffing two JSON objects that have the same data in different order.

Configurable indent

Choose 1, 2, or 4 space indentation to match your project's code style or editor settings.

Zero server calls

All processing runs in your browser. Your JSON data never leaves your machine.

Common JSON errors and how to fix them

These six errors account for the vast majority of invalid JSON we see. Each example below shows the broken input, the corrected version, and why the rule exists.

Trailing commamost common
✗ broken
{
  "name": "Alice",
  "role": "admin",
}
✓ fixed
{
  "name": "Alice",
  "role": "admin"
}

Trailing commas are valid in JavaScript and TypeScript but explicitly forbidden by RFC 8259. They account for the majority of parse errors we see — almost always copied from a JS object literal or a config file.

Single-quoted strings
✗ broken
{
  'name': 'Alice',
  'role': 'admin'
}
✓ fixed
{
  "name": "Alice",
  "role": "admin"
}

JSON requires double quotes everywhere — for both keys and string values. Single quotes are not valid, even though they work fine in JavaScript.

Unquoted keys
✗ broken
{
  name: "Alice",
  role: "admin"
}
✓ fixed
{
  "name": "Alice",
  "role": "admin"
}

Unlike JavaScript object literals, every key in JSON must be a double-quoted string. Bare identifiers are not allowed.

Comments
✗ broken
{
  // user config
  "debug": true,
  /* set by CI */ "env": "prod"
}
✓ fixed
{
  "_comment": "user config",
  "debug": true,
  "env": "prod"
}

JSON has no comment syntax — neither // nor /* */. This was intentional: Douglas Crockford removed comments from the spec to prevent them from being used as parsing directives. If you need annotations, add a "_comment" key.

Non-JSON values
✗ broken
{
  "retries": undefined,
  "ratio": NaN,
  "limit": Infinity
}
✓ fixed
{
  "retries": null,
  "ratio": 0,
  "limit": 1e308
}

JSON only supports six types: string, number, boolean, null, object, and array. undefined, NaN, and Infinity exist in JavaScript but have no JSON equivalent. Replace with null or a valid number.

Mismatched brackets
✗ broken
{
  "ids": [1, 2, 3
}
✓ fixed
{
  "ids": [1, 2, 3]
}

Every [ must close with ] and every { must close with }. The validator shows the exact line where the mismatch occurs — look for the deepest unclosed bracket, not just the line the error reports.

JSON syntax rules

JSON is defined by RFC 8259. These are the rules that determine whether a document is valid. The "why" column explains the non-obvious ones.

TypeRuleWhy
StringsDouble-quoted only: "value"
NumbersInteger or float — no leading zeros, no NaN, no InfinityNaN and Infinity are JavaScript-specific; they have no representation in the JSON spec.
BooleansLowercase literals: true or false
NullLowercase literal: null
ArraysOrdered list of values: [1, "two", true]
ObjectsUnordered set of key/value pairs: {"k": "v"}Key order is not guaranteed. Never rely on insertion order when parsing JSON across different environments.
KeysMust be double-quoted strings
CommentsNot allowed — // and /* */ both cause a parse errorDeliberately excluded from the spec. Use a "_comment" key if annotations are needed.
Trailing commasNot allowed after the last element in an array or objectValid in JS/TS but forbidden in JSON. The most common source of parse errors.

Related tools

  • Diff CheckerCompare two JSON bodies side-by-side after formatting — sort keys first so only real data changes show up.
  • Hash GeneratorCompute SHA-256 or other digests of payloads for file integrity and API checksums.

Frequently asked questions

What is a JSON formatter?

A JSON formatter takes raw or minified JSON text and rewrites it with consistent indentation and line breaks so it is easier to read and debug. It also validates the syntax against the JSON specification (RFC 8259) and reports any errors.

Is this JSON formatter free?

Yes. The tool is completely free to use with no account, no rate limits, and no data sent to a server. All formatting and validation runs locally in your browser.

What is the difference between formatting and validating JSON?

Formatting changes the whitespace — it makes JSON human-readable without changing the data. Validating checks whether the JSON is syntactically correct per the JSON specification. This tool does both simultaneously.

Can I use this tool to minify JSON?

Set the indent size to 1 in the settings panel. The output will use minimal whitespace, reducing payload size for API responses and storage.

Why does my JSON show a parse error?

The most common causes are: a trailing comma after the last property, single-quoted strings instead of double-quoted, unquoted object keys, JavaScript comments, or a missing closing bracket. The error bar shows the exact character position.

What is JSON tree view?

Tree view renders JSON as a collapsible node hierarchy instead of raw text. Each object and array is expandable, making it easy to navigate large or deeply nested structures like API responses without scrolling through thousands of lines.

Does sorting keys change my JSON data?

No. The JSON specification defines objects as unordered collections, so key order carries no semantic meaning. Sorting alphabetically is cosmetic — it makes it easier to compare two objects or locate a specific property.

Is it safe to paste sensitive data into this tool?

Yes. The tool runs entirely in your browser using the native JSON.parse API. No data is transmitted to any server, logged, or stored. You can verify this by opening your browser's network tab while using the tool.