StringToolsStringTools

JSON Formatter & Validator

Paste your raw JSON to format, validate, and prettify it instantly. Processing happens entirely in your browser.

Mitul MandankaFounder, Progragon Technolabs · 15+ years building software
Updated June 20266 min read
Input0 chars
Formatted output will appear here...

TL;DR

Paste any JSON above, click Format for pretty output or Minify for the smallest valid string. Parsing happens client-side using the browser's native JSON.parse, which is strict ECMA-404 — comments and trailing commas will fail with a precise error position. Use the error line/column to jump to the bad character in your source.

JSON edge cases this formatter actually handles

Most online formatters are thin wrappers around JSON.parse. That works for the easy cases but silently misbehaves on the ones below — the ones that actually show up in production logs. Here is exactly how this tool behaves:

1. Large integers (BigInt precision loss)

JavaScript numbers are 64-bit floats. Any integer above 2^53 (9,007,199,254,740,992) silently loses precision when parsed. A Twitter snowflake ID like 1234567890123456789 becomes 1234567890123456800.

Input:   { "tweetId": 1234567890123456789 }
Output:  { "tweetId": 1234567890123456800 }  // ← precision lost

Workaround: quote the ID as a string before formatting, or use JSON.parse with a reviver in your own code.

2. Trailing commas (JSON5) and comments (JSONC)

Strict JSON does not allow either. tsconfig.json, VS Code settings, and many config files are technically JSONC. Pasting them here will throw "Unexpected token / in JSON" or "Unexpected token } in JSON".

// This is a comment    ← JSONC, fails JSON.parse
{
  "strict": true,        ← trailing comma, fails JSON.parse
}

Strip comments and trailing commas first, or use a JSONC-aware parser in your editor.

3. NaN, Infinity, and undefined

None of these are valid JSON values. A backend that serializes {"score": NaN} will fail parsing here — typically the bug is on the server. Python's json.dumps(allow_nan=True) emits NaN by default, which is the most common source of this error in API responses.

4. Unicode escapes and emoji

Strings containing 😀 (surrogate pair for 😀) round-trip correctly. Lone surrogates like \uD83D without their pair will format but produce a string the receiver cannot decode — this tool does not silently fix it, by design.

5. Key order preservation

Insertion order is preserved (per ECMA-262 spec since 2020). Keys that look like integers ("0", "1") sort to the front in some engines — this is a V8 quirk, not a bug in your data.

Decoding the 5 most common JSON parse errors

When the formatter shows a red error, the message text and position are precise. Here is what each of the common messages actually means and the usual cause.

"Unexpected token < in JSON at position 0"

The server returned HTML (often a 404 or login redirect) but your code expected JSON. The first < is from <!DOCTYPE html>. Check the network tab — the response is probably a 4xx or 5xx page.

"Unexpected end of JSON input"

The body was truncated mid-stream. Common causes: response gzip middleware closing the stream early, hitting a server timeout, or copying only part of a multi-line payload.

"Unexpected token } in JSON" (or ])

Trailing comma before the closing brace. Most editors and linters allow it; JSON.parse does not. Either remove the comma or run the source through a JSONC-aware tool.

"Unexpected token N in JSON" (typically NaN or null typo)

Either an unquoted NaN from a Python/Pandas serializer, or a literal misspelled as Null or NULL. JSON literals are case-sensitive: only null, true, false are valid.

"Bad control character in string literal"

A raw newline, tab, or other control character inside a string without escaping. Usually a Windows clipboard mangling \r\n, or pasting a multi-line log message into a JSON string field without escaping.

How developers use a JSON formatter day-to-day

Inspecting a curl response. curl -s api/users | pbcopy, paste here, format. Faster than piping through jq if you only need to read it once.

Cleaning a webhook payload before sharing. Format, then manually scrub PII (email addresses, tokens) before pasting into a Slack thread or GitHub issue.

Validating a package.json after a merge conflict. Conflict markers (<<<<<<<) left in the file produce the "Unexpected token <" error at the exact position — you spot the conflict instantly.

Comparing two API responses. Format both with the same indentation, then drop into the Diff Checker for a clean side-by-side.

Sanity-checking a Postman export. Postman's Copy as cURL sometimes wraps the body in escaped quotes. Format reveals the structure and surfaces the escapes.

When NOT to paste JSON into an online tool

Even though this tool runs entirely in your browser and we never see your data, there are cases where you should not use any online formatter:

  • Anything subject to HIPAA, PCI, or GDPR data-residency rules. Use a local tool like jq, fx, or VS Code's built-in formatter. Your compliance team will ask where the data went.
  • Files above 10 MB. Your browser can handle it, but pasting locks the tab. Pipe through jq or python -m json.tool in a terminal.
  • Production credentials embedded in the payload. Even client-side, you risk leaving them on a clipboard manager. Strip secrets first.

We mention this because we'd rather lose a pageview than have someone leak a token.

Frequently asked questions

Why does my JSON show "Unexpected token < in JSON at position 0"?

Almost always: the response you pasted is HTML, not JSON. The leading < is from <!DOCTYPE html> or <html>. Check your request — common causes are an expired auth token (server returns the login page), a 404, or a CORS preflight failure where the error page is HTML.

Can this format JSON with comments (JSONC) or trailing commas (JSON5)?

No, by design. This tool uses strict ECMA-404 JSON via JSON.parse. JSONC and JSON5 are different specifications. If you need to format a tsconfig.json or VS Code settings.json, use your editor's built-in formatter instead — it understands JSONC.

Does this preserve large integers like Twitter snowflake IDs?

Numbers above Number.MAX_SAFE_INTEGER(2^53 − 1) lose precision because JavaScript represents all numbers as 64-bit floats. If you control the producer, send the ID as a quoted string. If you don't, quote it manually in the raw text before pasting.

Why does my Postman response paste in as a single line?

Postman serializes the response body as a single-line string when you copy it. That's actually the perfect input for this formatter — paste it as-is and click Format. The output will be properly indented.

Is my JSON sent to your server?

No. The site is a static export — there is no backend that could receive your data. All parsing, formatting, minifying, and validating runs in your browser's JavaScript engine. You can verify this in DevTools → Network: pressing Format triggers zero outbound requests.

Can I sort object keys alphabetically?

Not in this tool today — insertion order is preserved. If you need sorted keys (useful for snapshot tests and deterministic diffs), use jq --sort-keys locally, or run JSON.stringify(obj, Object.keys(obj).sort(), 2) in your browser console.