The JSON Escape & Encoding Cheat Sheet

The string escapes that actually exist, the numbers that lie to you, the invisible characters that break parsers, and the real differences between JSON, JSON5, JSONC and NDJSON. Every tool recommended below is 100% client-side — nothing you paste ever leaves your browser.

1 · The complete JSON escape table

JSON strings allow exactly eight escape forms. Anything else starting with \ is invalid — a surprisingly common cause of validator errors after hand-editing config files.

EscapeCharacterNotes
\"Double quote U+0022Mandatory — a bare " ends the string
\\Backslash U+005CMandatory — a bare \ starts an escape
\/Solidus /Legal but optional; mostly a habit from embedding JSON in <script> tags
\bBackspace U+0008Rarely seen in the wild
\fForm feed U+000CShows up in legacy mainstream-format exports
\nLine feed U+000AReal newlines inside a string are illegal — use this
\rCarriage return U+000DWindows line endings inside strings must be escaped
\tTab U+0009Pasting a literal tab from a terminal breaks strict parsers
\uXXXXUnicode code unitFour hex digits, BMP only — see surrogate pairs below
Test any escape sequence round-trip with the JSON escape tool (minimal or ASCII-safe \uXXXX mode) and JSON unescape (which validates the result instead of silently returning garbage).

2 · Unicode: surrogate pairs and invisible characters

3 · Number traps: where JSON silently loses data

PatternWhat happensSafe practice
0.1 + 0.2 != 0.3IEEE-754 doubles; money, coordinates and rates driftSerialize monetary values as strings, or round at the boundary
Integers above 2^53 - 1 (9007199254740991)9007199254740993 parses to ...992 in every JS runtime — snowflake IDs, transaction IDsShip big IDs as strings; the validator flags lossy integers before they reach your code
NaN, Infinity, -InfinityNot JSON. JSON.stringify quietly emits null for themUse null explicitly, or a sentinel string
0x1F, 017, +5, .5, 5.All invalid — no hex, no octal, no leading +, no bare fractionNormal decimal form only
1e999Grammatically legal, unrepresentable — JS evaluates it to InfinityClamp at the producer
Debugging a generated client instead? The same errors show up as wrong types in code generation — Java, C#, Python and Rust mappings all handle the 2^53 boundary differently. More on that in what code generators assume about your JSON.

4 · The JSON-in-JSON double-escape

The most confusing sight in debugging: a value that looks like "{\"a\": 1}". That's a JSON document serialized as a string inside another JSON document — logs, webhooks and message queues do this constantly. Strip one level of escaping and re-parse. Two signs you're looking at it: backslashes before every quote, and a validator that parses the envelope fine but the payload is one opaque string. The unescape tool performs exactly this peeling and validates what's underneath; for nested payloads use jq in the browser (.payload | fromjson) as described in running real jq client-side.

5 · JSON vs JSON5 vs JSONC vs NDJSON

Four "JSON" formats with different strictness. Picking the wrong validator wastes hours — the errors read as nonsense when you check one dialect against another's grammar.

JSON (RFC 8259)JSON5JSONCNDJSON
Comments✗✓ // and /* */✓✗
Unquoted keys✗✓✗✗
Single-quoted strings✗✓✗✗
Trailing commas✗✓✗✗
Multiple documents✗✗✗✓ one per line
Typical homeAPIs, data exchangehuman-written configVS Code / TS configslog streams, bulk imports

6 · Base64 inside JSON

Binary payloads (images, crypto, PDFs) travel inside JSON as base64 strings. Three things bite people:

7 · Schemas: catching all of the above before runtime

Escape tables and number ranges are exactly the kind of contracts a JSON Schema expresses: pattern for strings, maximum / multipleOf for numbers, format for base64. Generate a first draft from a sample with the schema generator, then validate incoming payloads with the AJV-based validator — the workflow is walked through in how to validate JSON against a schema and generating draft-2020-12 schemas from examples.

Why every tool here is browser-only: the fastest way to leak API keys and PII is pasting real payloads into a web tool that processes them server-side. Everything linked on this page parses in your browser tab — the privacy model is explained in how jsonformatter.app keeps data local, and the FAQ covers the edge cases in jsonformatter.app FAQ.