Skip to main content
Tools Harbor

JSON Formatter & Validator

Pretty-print, minify and validate JSON with line-accurate error messages.

This tool re-indents JSON for readability, strips it down to a single compact line, or tells you the precise character where it stops parsing — using the same JSON.parse your browser, and your own code, would run. Paste JSON, pick 2- or 4-space indent, and click Format or Minify; there’s no separate “check syntax” button because both actions parse the input first. Nothing you paste is sent anywhere — the whole round trip happens in memory in the tab you’re looking at.

Quick reference

ActionWhat happens
FormatRe-indents the parsed value with your chosen spacing (2 or 4 spaces)
MinifyRe-serializes with zero indentation — one line, no extra whitespace
Indent controlA dropdown fixed to 2 or 4 spaces; it only affects Format, Minify ignores it
On successA green “Valid JSON” note appears above the output box
On failureA red “Invalid JSON: …” note shows your browser’s own parser error; the output box stays empty
CopyA Copy button appears under the output once there is one, and copies it to your clipboard
Size limitNone enforced by the tool itself — you’re bounded by your browser tab’s available memory

What does “valid JSON” actually mean?

JSON has one specification — RFC 8259 — and it is stricter than the JavaScript object literals it resembles. Object keys and every string must use double quotes, never single quotes. A trailing comma after the last item in an array or object is not allowed, even though most JavaScript engines tolerate it in source code. There is no comment syntax, so // a note or /* a block */ inside a JSON document is a parse error, not a JSON feature. Booleans and null must be the lowercase true, false, null — not Python’s True, False, None. Numbers can’t carry a leading +, and a digit sequence can’t start with 0 unless the whole number is 0.

This formatter enforces exactly that specification, because under the hood it calls your browser’s native JSON.parse rather than a lenient parser of its own. If your source is a JavaScript config file, a Python dict someone dumped with single quotes, or JSON5/JSONC with comments, it will fail here even though it loaded fine wherever it came from. If you’re actually working with YAML — a Kubernetes manifest, a CI pipeline file, a docker-compose.yml — convert it with the JSON to YAML converter first; that tool speaks both formats, this one speaks strict JSON only.

How do I fix a JSON parse error?

  1. Click Format or Minify — either one runs the input through the parser; there’s no separate validate step to remember.
  2. Read the message in the red box. It’s the parser’s own wording, and it always includes a character position — in Chrome, Edge and other Chromium-based browsers that position also comes with a line and column number.
  3. Count to that position in your source (most code editors show the cursor’s line and column in the status bar) and look at what sits right before and after it — the problem is almost always adjacent, not at the position itself.
  4. Fix that one spot, using Common mistakes below if the symptom looks familiar, then click Format again.

Worked example. Paste this:

{"name": "Ada", "role": "admin",}

Click Format, and the red box reads:

Invalid JSON: Expected double-quoted property name in JSON at position 32 (line 1 column 33)

Position 32 is the closing }. The parser consumed the comma after "admin" and, expecting another key, landed on the brace instead — so it reports the brace’s position, one character past where the real mistake is. Delete that trailing comma:

{"name": "Ada", "role": "admin"}

Format now succeeds:

{
  "name": "Ada",
  "role": "admin"
}

Formatting vs minifying vs validating

Two of the controls transform your input, not three. Format re-indents with your chosen spacing so nested structures are readable — useful for diffing two API responses side by side, or preparing a clean example for documentation. Minify re-serializes with zero indentation, collapsing the whole document to one line — useful for embedding JSON in a URL query parameter, shaving bytes off a request body, or writing one record per line to a log file. There’s no third Validate button because both of the others require a successful parse before they can produce any output at all: see the “Valid JSON” note and your input parsed; see the red note and it didn’t. Click Format on JSON that’s already formatted the way you want, and you’ve effectively just validated it — the output will be structurally identical to the input.

Minify only removes whitespace; it never touches the data itself. It won’t shorten key names, drop null fields, or reorder anything — that’s a different kind of transform. If you need to minify more than JSON — a bundled .js or .css file sitting next to your API payloads, say — the code minifier handles those languages; this tool only understands JSON syntax and will reject anything else.

Once your JSON is confirmed valid, two adjacent jobs come up constantly. If someone downstream needs the data in a spreadsheet, the JSON to CSV converter flattens an array of objects into rows and columns. If you’re staring at a JWT and want to read its header and payload without base64-decoding it by hand first, the JWT decoder splits the token on its dots and decodes both segments straight to JSON for you — or, if you only need to decode a single base64url string, the base64 encoder/decoder does just that step on its own.

Common mistakes

Trailing commas. {"a": 1, "b": 2,} and [1, 2, 3,] are both valid JavaScript, neither is valid JSON. The parser reports it as an unexpected token or an unexpected property-name expectation right at the closing bracket — delete the last comma.

Unquoted or single-quoted keys. {name: "Ada"} and {'name': "Ada"} both fail the same way, with a message like “Expected property name or ’}’ in JSON at position 1.” Every JSON key is a double-quoted string; there’s no shorthand.

Comments left in from a JS or JSON5 source. JSON has no comment syntax at all. A // note or /* block */ anywhere in the document just reads as an unexpected token to the parser — strip comments before pasting, or reach for a JSON5-aware tool instead of this one.

NaN, Infinity, or undefined in the source text. These are legal JavaScript values but illegal JSON literals. JSON.stringify itself will never write them out — it turns NaN and Infinity into null and silently drops keys whose value is undefined — but if the literal word appears in text you’re pasting in, parsing fails with an unexpected-token error.

Leading zeros on numbers. {"code": 01} fails with “Unexpected number in JSON.” A JSON number can’t start with 0 followed by more digits. If the leading zero is meaningful, like a ZIP code, quote it as a string instead: {"code": "01"}.

Privacy

The JSON you paste here is often not throwaway sample data — API responses routinely carry access tokens, session identifiers, internal hostnames, or full user records. None of that text is sent anywhere. JSON.parse and JSON.stringify run synchronously in your browser’s own JavaScript engine, the same engine that would run this exact code if you pasted it into your app’s console instead. There’s no upload step to audit or skip, because no request is ever made; closing the tab clears everything, since nothing outlasts the page’s own memory.

Frequently asked questions

What counts as valid JSON?
Strict JSON (RFC 8259). That means: double-quoted keys and strings, no trailing commas, no comments, and true/false/null in lowercase. If your data comes from a JavaScript source, it may contain any of these non-standard features — this validator will flag them.
Can I format a JSON file with millions of entries?
The formatter runs entirely in your browser's memory, so there is no server-side size limit and no artificial cap coded into the tool. JSON.parse and JSON.stringify run synchronously on the main thread against whatever sits in a single textarea, rather than in streamed chunks, so how large a file feels comfortable depends on your device's available RAM and browser rather than a number this tool enforces.
Which is better: 2-space or 4-space indentation?
2 spaces is the convention for most JSON ecosystems today (npm package.json, most web APIs, many config files). Choose 4 spaces only when a downstream tool or team style guide demands it.
Is there a separate button just to check if my JSON is valid?
No — Format and Minify are the only two buttons that touch your input, and both validate as a side effect: each one has to successfully parse it before it can produce output. (A Copy button also shows up once there's output, but it only copies text to your clipboard — it doesn't parse anything.) If you just want a validity check, click Format or Minify and read whether the "Valid JSON" or "Invalid JSON" message appears.