How to Format JSON Online (Pretty Print, Validate, and Repair Broken JSON)
You paste a 400-line API response into your editor and it's one giant minified blob — no line breaks, no indentation, no way to tell where one object ends and the next begins. You need to format that JSON into something readable before you can debug it. Or worse: you're trying to parse JSON pulled from a log line and the parser keeps throwing “Unexpected token at position 1247” with no clue where the actual problem is.
In this guide you'll learn how to format JSON online for free, how to validate it (so you can catch broken JSON before it hits production), and how to repair common mistakes like missing commas and trailing commas using PDFFlare's JSON Formatter — 100% browser-based, your data never leaves your device.
Why Format JSON in the First Place?
Minified JSON is great for transport — fewer bytes over the wire — but terrible for humans. Pretty printing solves five real problems:
- Readability: A 4000-character single-line response becomes a 200-line tree you can scan top-to-bottom in seconds.
- Debugging:When the parser screams “Unexpected token at position 1247,” line numbers tell you which property is broken.
- Diffing:Git, code review tools, and your own eyes can't diff one-line JSON. Pretty printing makes meaningful diffs possible.
- Sharing: A formatted JSON snippet pasted into Slack or a bug ticket is something a teammate can actually read.
- Learning:If you're new to an API, formatted JSON is the fastest way to understand its shape.
How to Format JSON Online (Step by Step)
PDFFlare formats JSON entirely in your browser. Your data is never uploaded — safe for production payloads, API tokens, and PII.
- Open PDFFlare's JSON Formatter. No account, no signup.
- Paste your JSON into the left input pane. Anything from a 10-line config to a 50,000-line export works.
- Click Format. The output pane on the right shows your JSON pretty-printed with 2-space indentation, line numbers visible in both panes.
- Copy with one click. Use the Copy button or select and copy directly from the editor.
- Hit Validate if you just want to confirm the JSON is well-formed without changing it.
- Hit Repair if the JSON is broken — the tool will fix common syntax mistakes and produce valid JSON if it can.
Format vs Minify vs Sort Keys vs Repair: Which Do You Need?
The formatter exposes four actions because they solve different problems. Knowing which to pick saves time:
- Format (Pretty Print):Human-readable output with indentation. Use when you're reading or debugging.
- Minify:Removes all whitespace. Use when you're embedding JSON in a URL, a code string, or a network payload where bytes matter.
- Sort Keys:Alphabetically sorts every object's keys recursively. Critical for stable diffs — two semantically equal JSON files with keys in different orders produce zero diff after sorting.
- Repair: Best-effort fix for malformed JSON. Handles trailing commas, unquoted keys, single-quoted strings, and Python / JavaScript-flavoured pseudo-JSON.
Common JSON Errors and How to Fix Them
Most “invalid JSON” errors fall into a handful of buckets. PDFFlare's formatter pinpoints the line and column of the problem so you don't have to count characters.
Missing Comma
The single most common JSON error. Two object properties on consecutive lines without a comma between them. The error message says “Expected , or }” — open the formatter, paste, click Format, and the error pane points at the exact line. Add the comma, re-format, done.
Trailing Comma
You wrote [1, 2, 3,]with a comma after the last element. JSON forbids trailing commas (unlike JavaScript). Strict parsers reject it. PDFFlare's Repair button strips trailing commas automatically.
Unquoted Keys
You copied a JavaScript object literal into a JSON parser. JS allows { name: "alice" } , JSON requires { "name": "alice" } . Repair adds the missing quotes around all keys.
Single Quotes
JSON requires double quotes; you have single quotes. Common when pasting from Python or older JS code. Repair converts single-quoted strings to double-quoted ones, with proper escaping.
Comments
JSON has no comments. If your config-style JSON has // comments, parsers will reject it. Repair strips line and block comments before re-emitting.
Indent Style: 2 Spaces, 4 Spaces, or Tabs?
The formatter uses 2-space indentation by default — the de facto standard for JSON. A few notes on style:
- 2 spaces is the dominant convention. It saves horizontal screen space, deeply nested JSON stays readable, and most public APIs and SDKs emit 2-space output. Stick with this unless you have a specific reason not to.
- 4 spaces is sometimes used in older Python and Java codebases for consistency with their source files. It wastes horizontal space in deeply nested JSON — a 6-level-deep config indents 24 columns before you see content.
- Tabs render differently in different editors (typically 4 or 8 columns). For JSON checked into git, this causes inconsistency. Avoid for JSON.
- 0 spaces (minified)is for transport, not editing. Browsers, fetch clients, and curl all handle it; humans don't.
Working With Large JSON Files
A browser-based formatter can comfortably handle JSON up to a few megabytes. Past that, you'll see noticeable lag, and at tens of megabytes you'll exhaust memory. Some practical guidance:
- Up to ~500 KB: Instant. The formatter handles this without breaking a sweat — typical API responses, config files, and exports fit here.
- 500 KB to ~5 MB:A second or two of processing. Still fine; you'll see line-number gutters scroll smoothly.
- 5 MB to ~50 MB: Use with caution. Modern laptops can handle this, but mobile devices may struggle. Inspect a slice instead — copy a representative chunk into the formatter, leave the rest alone.
- Above 50 MB: Switch to a streaming command-line tool.
jqhandles arbitrarily large files; the browser does not.
JSON Lines (NDJSON / JSONL): A Special Case
Application logs and big-data exports often use JSON Lines — one JSON value per line, no array wrapper. Example:
{"user": "alice", "action": "login"}{"user": "bob", "action": "logout"}
This is notvalid JSON in the strict sense — there's no top-level array. To format JSON Lines, wrap the lines in [ and ] with commas between each entry, then run through the formatter. To split formatted JSON back into JSON Lines, the inverse: drop the brackets, join with newlines.
Common Scenarios
Reading an API Response
You hit an endpoint in Postman or curl, get back a wall of minified JSON. Paste it into the formatter, click Format, and the structure becomes obvious in seconds. For really big responses, follow up with PDFFlare's JSON Viewer for a collapsible tree.
Comparing Two API Responses
Sort keys on both, then either eyeball them side-by-side or run them through PDFFlare's JSON Diff for a structural comparison. Sorting is mandatory — without it, the diff is full of false positives caused by key ordering.
Embedding JSON in a Bug Ticket
Format first, then copy. A formatted snippet in a ticket is something a teammate can read and reason about. Minified JSON in a ticket is a wall of text nobody reads.
Cleaning Up Pseudo-JSON From a Log
Application logs sometimes emit JS-style object dumps with unquoted keys, single quotes, or trailing commas. Repair turns that into valid JSON in one click — much faster than fixing each issue by hand.
Best Practices for Working With JSON
- Always validate before parsing in code. A schema check via PDFFlare's JSON Schema tool catches malformed payloads before they crash production.
- Sort keys before checking JSON into git. Stable ordering means clean diffs. The Sort Keys button does this in one click.
- Minify for transport, format for editing.Don't check pretty-printed JSON into version control if it's only ever consumed by code — minify it to save bytes.
- Use 2-space indentation as the default. 4 spaces wastes horizontal space; tabs cause display inconsistencies. 2 spaces is the de facto standard for JSON.
Common Mistakes That Break JSON Parsing
Beyond syntax errors, a handful of subtler issues silently corrupt JSON or break parsers. Worth knowing about:
- Unicode BOM: Some editors prepend a Byte Order Mark (
) to UTF-8 files. Strict parsers reject it. Save without BOM, or strip it before parsing. - NaN, Infinity, and undefined: JavaScript has them; JSON does not. Serializing an object with
NaNviaJSON.stringifyproducesnull; some non-JS serializers emit literalNaNwhich then fails in JS parsers. Convert to numbers (or null) before serializing. - Bigint precision loss: JSON numbers map to JavaScript Number, which is a 64-bit float. Integers above
2^53 - 1lose precision. If your IDs are bigints, serialize them as strings to preserve exact values. - Date objects: JavaScript
Datestringifies to ISO 8601 — but only if you ranJSON.stringify. Manually building JSON from aDatecan produce a useless{}object instead. Convert withtoISOString()first. - Circular references:JS objects with circular references can't be serialized at all. Detect with a try/catch around
JSON.stringifyand either break the cycle or use a custom replacer.
Privacy: Your JSON Stays on Your Device
PDFFlare's JSON Formatter runs entirely in your browser. The parsing, formatting, and repair logic is JavaScript executed locally — your JSON never touches any server. This makes it safe for production API payloads, JSON containing API tokens, customer data, or anything else you wouldn't paste into a third-party server. Close the tab and the data is gone.
Wrapping Up
A formatter takes invalid, unreadable JSON and turns it into something you can actually work with. Add validation and repair on top, and you've got a one-stop tool for the 90% of JSON pain that comes up day to day.
Next time you're staring at a wall of minified JSON or a mysterious parser error, paste it into PDFFlare's JSON Formatter and you'll be unblocked in seconds.
Related Workflows
Adjacent tools you might find useful while working through this guide: JSON Formatter, JSON Viewer, and JSON Schema. They handle different parts of the same workflow and pair naturally with what we've covered here.
Related Tools
- JSON Viewer — browse big JSON as a collapsible tree
- JSON Diff — compare two JSON values structurally
- JSON Schema — generate or validate against a JSON Schema
- JSON Stats — inspect depth, key counts, and type breakdown
Privacy & Data Handling
PDFFlare's JSON formatter runs entirely in your browser — your JSON never leaves your device. That makes it safe for production payloads, internal API responses, snippets that contain access tokens, and anything else you'd normally hesitate to paste into a third-party online tool. There's no upload, no server-side storage, and no analytics on file contents. Your data stays local.
Wrapping Up
Formatting JSON online used to mean choosing between fragile parsers, watermarked output, or sites that quietly upload your data. PDFFlare's formatter gives you instant pretty-printing, minification, key sorting, validation with line/column error pointers, and a repair mode that fixes common syntax slip-ups — all in your browser, all free. Try it on your next stubborn JSON payload and you'll wonder why the standard workflow ever required anything more.