Skip to content

JSON Formatter — Beautify, Validate & Minify Online

Format, minify, or validate JSON instantly — free, private, and browser-based.

Last updated:

When to use a JSON formatter

Most of the time you want a JSON formatter, you already have JSON — it's just in a shape you can't read. Common cases:

  • An API response came back minified as a single line and you need to find one field buried eight levels deep.
  • A config file got edited by a tool that stripped whitespace, and you want to see the structure before you can diff it.
  • You're pasting a payload into a bug report and you want the reviewer to read it in five seconds, not fifty.
  • You copied a snippet from a log line and want to confirm it's actually valid before sending it anywhere.

A formatter solves the first three. A validator solves the last. This tool does both: paste once, click Format to beautify, Validate to check for errors, or Minify to collapse it back.

Common JSON errors and how to fix them

The browser's JSON.parse() strictly follows RFC 8259, which is why it's picky about things you might consider minor. The good news: every error message maps to a specific fix.

Unexpected token , in JSON at position N

A trailing comma — legal in JavaScript object literals, illegal in JSON.

{
  "name": "ada",
  "age": 36,
}

Remove the comma after 36.

Unexpected end of JSON input

A bracket, brace, or string was opened and never closed.

{ "items": [1, 2, 3 }

The array opened with [ but never closed. Usually a hand-edit or a copy-paste that clipped one line. Close the array, then the object.

Unexpected token ' in JSON at position 0

Single quotes where double quotes are required.

{ 'name': 'ada' }

JSON requires double quotes for both keys and string values. Most editors will swap them in one find-and-replace.

Bad control character in string literal

A raw newline, tab, or other control character inside a string.

{ "message": "line one
line two" }

Escape the newline with \n:

{ "message": "line one\nline two" }

Unexpected token a in JSON at position 0

You pasted a JavaScript object literal instead of JSON.

{ name: "ada", age: 36 }

Valid JavaScript, invalid JSON — the keys aren't quoted. Wrap every key in double quotes.

Strict JSON vs JSON5 vs JSONC

If you're frequently working with JSON that has comments or trailing commas, you're not working with strict JSON — you're working with a relaxed variant:

  • JSON5 — allows comments, trailing commas, unquoted keys, single quotes, and hex numbers. Used by Babel, Parcel, and some database config files.
  • JSONC (JSON with Comments) — adds line and block comments. Used by VS Code's tsconfig.json and settings.json.
  • HJSON — human-oriented dialect with unquoted values and comments. Rare outside its own ecosystem.

This formatter targets strict JSON only. If you need to work with JSON5 or JSONC, strip the relaxed syntax first, or use a parser built for that variant.

How this formatter handles large files

The formatter runs entirely in your browser using JSON.parse() and JSON.stringify(). There's no upload and no server round-trip, which means:

  • No size limit from us. The practical ceiling is whatever your browser tab can allocate — typically several hundred megabytes before you hit memory pressure on desktop.
  • Validate and Format are the same work. Both build the full object tree. There's no "light validator" that avoids the parse cost.
  • Sensitive data never leaves. API responses with auth tokens, database dumps, user PII — all stay on your machine. This is the whole reason the tool exists.

If your JSON is genuinely enormous (a 500 MB log export, for example), a streaming parser like stream-json in Node or jq -c on the command line will serve you better than any browser-based tool, ours included.

Keyboard workflow

The tool is designed for paste-in, format, copy-out:

  1. Ctrl/Cmd+A in the input to select everything, then paste your JSON over the top.
  2. Click Format to beautify, or Minify to collapse.
  3. Ctrl/Cmd+A on the output, Ctrl/Cmd+C to copy.

If you work with curl a lot, piping a response straight to your clipboard means you can paste it into the formatter in one step: curl -s URL | pbcopy on macOS, or curl -s URL | xclip -sel clip on Linux.

Related JSON tools on CodeBoxTools

This formatter is the entry point to a cluster of JSON tools on the site:

  • JSON Diff — compare two JSON objects and see exactly which keys changed, with paths.
  • JSON to CSV — export a JSON array as a spreadsheet with flattened nested keys.
  • JSON to YAML and YAML to JSON — round-trip between formats.
  • JSON to TypeScript — generate type definitions from a sample payload.
  • JSON to XML — structural conversion with attribute handling.

Frequently Asked Questions

What's the difference between Format and Minify?
Format adds indentation and line breaks to make JSON human-readable. Minify removes all unnecessary whitespace to create the smallest possible output — useful for APIs and storage.
How does validation work?
The validator uses JSON.parse() which strictly follows the JSON specification (RFC 8259). It will catch missing quotes, trailing commas, single quotes, and other common syntax errors.
Is my JSON data kept private?
Yes. This tool runs entirely in your browser. Your JSON is never sent to any server, making it safe for sensitive data like API responses and configuration files.
What does 'pretty print' JSON mean?
Pretty printing is another term for formatting or beautifying. It adds indentation and line breaks to collapsed JSON so the structure is readable. This tool's Format button pretty-prints with 2-space indentation — equivalent to JSON.stringify(data, null, 2) in JavaScript.
Why does JSON.parse fail on my string?
The most common causes are trailing commas, single quotes instead of double quotes, unquoted keys, unclosed brackets, and literal newlines inside strings. Paste your input and click Validate — the error message reports the exact character position where parsing stopped.
Can I format JSON with comments or trailing commas?
Not with this tool. It targets strict JSON per RFC 8259, which forbids both. If you're working with JSON5 (comments, trailing commas, unquoted keys allowed) or JSONC (comments only — the dialect VS Code uses in tsconfig.json and settings.json), you'll need to strip the relaxed syntax first, or use a parser built for that variant.
How do I minify JSON before sending it to an API?
Click the Minify button. The tool strips every byte of unnecessary whitespace and outputs the smallest valid JSON representation. This is what most HTTP APIs expect on the wire — pretty-printing is only for humans reading the payload.

Related Tools