DevFormatLab

JSON Formatter

Format · Minify · Validate

Format, minify and validate JSON locally. Errors are highlighted with line and column.

Font15px
109 chars
InputValid
OutputObject · 3 keys
{{3}
"": "",
"": [[4]
],
"":
}

Your JSON is processed entirely in your browser — nothing is uploaded.

What is a JSON Formatter?

A JSON formatter (sometimes called a JSON pretty-printer, JSON beautifier, or JSON validator) takes raw JSON text — typically a single long line copied from an API response, a log file, or a configuration file — and reformats it with consistent indentation and line breaks so it becomes easy to read, review, and debug. A good formatter also validates the syntax against RFC 8259, pointing out exactly where a missing comma, unbalanced bracket, single-quoted string, or invalid escape sequence is. And when you need the opposite direction, it can minify pretty-printed JSON back into a compact one-line form to save bytes on the wire. DevFormatLab's JSON Formatter is built for this everyday loop: paste, beautify, fix, minify, ship. It supports 2-space, 4-space and tab indentation; live character and byte counters; a switchable tree view that lets you collapse deeply nested objects and arrays so you can navigate a 10,000-line payload in seconds; and a strict parser that highlights the exact line and column of any syntax error. There is no upload step and no server round-trip — the formatter runs entirely in your browser using the native JSON.parse and JSON.stringify primitives, so sensitive payloads (access tokens, customer records, internal API responses) never leave your device. Once the page has loaded, it keeps working offline, which makes it safe to use on locked-down corporate networks or while traveling. Whether you're debugging a webhook, prepping a fixture for a unit test, embedding a config snippet into a Markdown doc, or just trying to understand someone else's API, a fast, private JSON formatter belongs in every developer's toolbox.

Features

  • Pretty-print with 2 / 4 / tab indentation
  • One-click minify (remove all whitespace, save 30–60% bytes)
  • Strict RFC 8259 validation with line and column error reporting
  • Collapsible tree view for deeply nested objects and arrays
  • Live character and byte counter to track payload size
  • Copy / Download / Apply-to-input shortcuts for fast iteration
  • 100% client-side — works offline once loaded, zero uploads

How to use

  1. Paste raw or already-formatted JSON into the input panel on the left. The status pill at the top turns green when the document parses cleanly.
  2. Pick an indentation: 2 spaces is the most common (npm, GitHub, most API docs), 4 spaces matches the Python / PEP 8 style, tab matches Go's gofmt-style configs.
  3. Need a compact payload for production or a URL parameter? Click Minify — every newline and indent is removed without changing a single value.
  4. Switch to Tree view for large documents: click the chevrons to collapse arrays and objects, hover for path tooltips, and use Expand all / Collapse all from the toolbar.
  5. If the JSON is invalid, the exact line and column of the parse error appears at the bottom (for example, "Unexpected token } at line 7 column 3") — click it to jump there.
  6. Use Copy to put the result on your clipboard, Download to save it as .json, or Apply to input to reuse the output as the next input (handy for round-trip tests).

Frequently Asked Questions

How do I fix "SyntaxError: Unexpected token } in JSON at position 42"?

That message means a structural character (usually a trailing comma) appears where JSON does not allow it. Click the error line indicator at the bottom of the formatter — it jumps the cursor to the exact line/column. The most common culprits are: • Trailing comma: {"a": 1, "b": 2,} → remove the last comma → {"a": 1, "b": 2} • Single quotes: {'a': 1} → use double quotes → {"a": 1} • Unquoted key: {a: 1} → quote it → {"a": 1} • Stray comment: // note inside JSON → delete it (use JSON5 instead if you really need comments) After fixing, the status pill at the top of the input panel turns green and the formatted output appears on the right.

Why does "Unexpected end of JSON input" appear?

Your JSON is truncated — typically a missing closing } or ]. The formatter shows the position where the parser ran out of characters. Quick checks: • Count opening vs. closing braces with Ctrl+F • Look for a stray comma before EOF: [1, 2, 3, ← drop it • If you pasted from a terminal, make sure the response was not cut off Use the Format button after fixing — a successful parse means the structure is now balanced.

What does "Bad escaped character in string" mean?

Inside a JSON string only these escapes are valid: \", \\, \/, \b, \f, \n, \r, \t and \uXXXX. Anything else (for example \x41 or a raw backslash before a letter) is rejected. Example fix: {"path": "C:\Users\me"} ← invalid {"path": "C:\\Users\\me"} ← valid (each backslash doubled) If you are embedding JSON inside another language's source code, do the escaping at the outer layer, not inside the JSON.

How can I minify JSON for production / smaller payloads?

Paste your JSON, click the Minify button on the toolbar. All whitespace, line breaks and trailing zeros are removed; semantics are preserved. The character count under the output panel shows the saved bytes. For an API response you can typically cut 30–60% of the size without changing a single value.

Does this support JSON5, JSONC or comments?

Not yet — DevFormatLab follows strict RFC 8259. If your source has // or /* */ comments or trailing commas, the parser will reject it. Workarounds for now: • Remove comments with a regex: /\/\/.*$/gm and /\/\*[\s\S]*?\*\//g • Or paste into a JSON5 → JSON converter first Native JSON5 / JSONC support is on our roadmap.

Is my JSON sent to a server?

No. All parsing, formatting and minification happens in your browser via JSON.parse / JSON.stringify. The page works offline once loaded — feel free to disconnect the network and verify.

Related tools

Canonical: https://devformatlab.com/en/json-formatter