Skip to content
DeveloperRuns in your browserPopular

JSON Formatter & Validator

Pretty-print JSON with your chosen indent and see exactly where errors are — a JSON formatter that points at the fault.

Input
No upload needed — instant
Privacy
Nothing is uploaded
Cost
Free · no sign-up · no watermark

Loading tool…

The tool is loading its code on your device. This happens once and is cached for later visits.

Processed entirely on your device

Everything you type or paste is handled by JavaScript running in this tab. No request is sent, nothing is logged and nothing is stored. Close the page and it is gone.

Overview

About the JSON Formatter & Validator

Format, validate and beautify JSON online. Precise error positions, 2 or 4 space or tab indentation, key sorting and a collapsible tree view — all client-side.

A JSON formatter is the first tool anyone reaches for when an API response refuses to parse. JSON is simple enough that everyone thinks they can eyeball it, and large enough that nobody actually can. A JSON formatter is the difference between finding a missing comma in two seconds and finding it in ten minutes — and because formatting requires a complete parse, the same operation doubles as validation. If the document formats, it parses.

Why pretty print JSON instead of reading it raw? JSON from a server arrives as one long line of compact text — correct for the network, useless for a human. When you format JSON, every level of nesting moves one step to the right and the shape of the data becomes visible at a glance. Reviewing an API payload, checking a config file or attaching a sample to a bug report are all faster with formatted JSON, and pasting it into a JSON formatter is the quickest syntax sanity check there is.

What "valid JSON" actually requires

The specification is small and unforgiving:

  • Strings must use double quotes. Single quotes are invalid.
  • Object keys must be quoted strings. Unquoted keys are JavaScript, not JSON.
  • No trailing commas. [1, 2, 3,] and {"a": 1,} both fail.
  • No comments. // and /* */ are not part of JSON — JSONC and JSON5 add them, and many config parsers accept them, but a strict parser will not.
  • Only six value types: object, array, string, number, true, false, null. Not undefined, not NaN, not Infinity, not dates.
  • Numbers cannot have a leading plus, cannot be hexadecimal, and cannot have a leading zero before a digit sequence.

Most "why is my JSON broken" questions are answered by that list.

Reading the error output from the JSON validator

A native parse failure reports a character position, which is useful but not directly navigable. This JSON validator converts that offset into a line and column number and shows the surrounding text with a caret under the offending character. When the reported position is the end of the document, the real problem is almost always an unclosed bracket earlier — count your braces.

The failures a JSON syntax checker meets most often, in rough order of frequency:

  • A trailing comma after the last element of an object or array.
  • A string opened with a single quote, or smart quotes pasted from a document or chat app.
  • An unquoted key, usually written by someone thinking in JavaScript object literal syntax.
  • An unterminated string, where a missing closing quote swallows the rest of the document.
  • A literal line break inside a string, which JSON does not allow and which must be written as an escaped sequence instead.

Each of these is a one-symbol fix once the validator has pointed at the exact position — which is precisely why a JSON validator with line and column reporting beats a parser that throws a bare "unexpected token".

Indentation choices in a JSON formatter

Two spaces is the prevailing convention in JavaScript and Node ecosystems and what JSON.stringify(value, null, 2) produces.

Four spaces is common in Python and Java shops and easier to read in deeply nested documents.

Tabs keep indentation width a viewer preference rather than a file property.

Whatever you choose, be consistent — mixed tabs and spaces are invisible in most editors and maddening in diffs.

Sorting keys in formatted JSON for diffing

Alphabetically sorted keys turn a structural comparison into a line comparison. Two versions of the same config diff cleanly line by line instead of showing a whole object as changed because a member moved. This is why canonical JSON representations used in signing schemes specify a key order. Sorted formatted JSON is also easier to scan for one specific key, because your eye can run down the alphabetical sequence instead of reading every line.

Big integers

JSON has no integer type distinct from number, and JavaScript numbers are IEEE-754 doubles. Any integer above 2^53 − 1 (9007199254740991) loses precision on parse. Database IDs and snowflake identifiers routinely exceed that. The large-integer option rewrites long numeric literals as strings before parsing so they survive formatting intact — but remember that the resulting document is no longer the same JSON, so use it for inspection rather than for round-tripping.

The JSON tree view for large payloads

Formatting a document makes it readable; a tree view makes it navigable. Collapsing and expanding nested objects and arrays lets you explore a deep API response without scrolling through thousands of lines of pretty-printed text. When a payload contains a data array with five hundred records, the JSON tree view folds it away, lets you open exactly one record to inspect its fields, and folds it back — something no amount of indentation makes pleasant.

The tree view also labels every node with its type and, for arrays, its length. That is usually enough to answer "why is this payload so large?" without any further tooling, and it doubles as a JSON viewer when you only need to look, not edit.

Format, validate and inspect in one place

The whole loop — format JSON, validate JSON, sort keys, explore the tree, copy or download the result — runs in your browser with no upload. That privacy detail matters more than it sounds: real payloads contain auth tokens, user records and internal endpoint names that have no business travelling to a third-party server. A JSON formatter is a small tool, but a client-side JSON formatter is a small tool that cannot leak anything.

Common situations where a JSON formatter saves the day:

  • An API returns a wall of minified JSON and you need to find one field inside it.
  • A config file fails to load and the runtime error message is useless.
  • A webhook body needs to be inspected before you trust it.
  • Two versions of a document need comparing after sorting keys.
  • A large response needs to be navigated rather than read end to end.

Step by step

How to use the JSON Formatter & Validator

  1. Paste your JSON into the input panel, or drop a .json file onto it.

  2. Press Format — valid JSON is pretty-printed instantly.

  3. If it is invalid, read the error message: it names the character position and the line.

  4. Choose indentation, toggle key sorting, or switch to the tree view.

  5. Copy the formatted output or download it as a .json file.

Why use it

Benefits and common use cases

What this tool is good for, and what it deliberately does not try to do.

Errors with a position, not just a message

Reports the exact character offset, line and column, plus a snippet of the surrounding text — so you find the missing comma rather than scanning the whole document.

Validates as it formats

Formatting is impossible without parsing, so a successful format is proof the JSON is syntactically valid. No separate validation step needed.

Tree view for large payloads

Collapse and expand nested objects and arrays to navigate a deep API response without scrolling through thousands of lines.

API responses stay on your machine

Payloads frequently contain tokens, user records and internal endpoints. Parsing happens in your tab, so nothing is posted anywhere.

Questions

Frequently asked questions

Short, honest answers about quality, limits and privacy.

Why is my JSON invalid when it looks correct?

The usual culprits: a trailing comma after the last item in an object or array, single quotes instead of double quotes, unquoted keys, JavaScript-style comments, the values undefined or NaN, or smart quotes pasted from a document or chat app.

Does this handle JSON with comments (JSONC)?

The strict parser rejects comments because they are not valid JSON. A toggle strips // and /* */ comments before parsing so JSONC files — tsconfig.json, .vscode settings, eslint configs — can still be formatted and inspected.

What does sorting keys do, and is it safe?

It reorders object members alphabetically, which makes two versions of a document easy to diff. It is safe for data but not for formats where key order is significant, such as JSON-LD in some processors or signature canonicalisation schemes.

Is there a size limit on the JSON I can format?

No imposed limit. The constraint is browser memory and parsing time — documents beyond a few megabytes will still work but the tree view may become sluggish. Very large payloads are better handled with jq on the command line.

Are numbers or precision changed by formatting?

The tool parses with the native JSON parser, so numbers beyond 2^53 lose precision exactly as they would in any JavaScript environment. A large-integer preservation option keeps long numeric literals as strings so IDs from databases survive intact.