JSON Lens Free online JSON toolkit
X ↗

Online JSON Formatter, Validator & Tree Viewer

Paste JSON or an escaped JSON string — auto-repair fixes quotes, trailing commas & comments, Unescape turns "{\"a\":1}" back into JSON, and a collapsible tree with JSONPath queries helps you explore any structure. Everything runs in your browser — nothing is uploaded.

Input 0 B
1
Waiting for input…

Developer's guide

Everything about JSON formatting, escaping and debugging — with copy-paste examples.

What is valid JSON? A 60-second cheat sheet

JSON (RFC 8259) is strict. These are the rules people break most often:

  • Keys must use double quotes. {name: 1} and {'name': 1} are invalid — write {"name": 1}.
  • No trailing commas. [1, 2, 3,] fails. Arrays and objects end without a comma.
  • Strings use double quotes only, and only these escapes: \" \\ \/ \b \f \n \r \t \uXXXX. A raw newline inside a string is invalid — use \n.
  • Literal values are fixed: true / false / null. Python's True/None, JS undefined, NaN and Infinity are not JSON.
  • No comments. // and /* */ are not allowed (JSON5/JSONC add them back).
  • Numbers: no leading zeros (01), no hex (0x1F), exponents allowed (1.5e10).
  • Top level can be any value: object, array, string, number, true, false, null.

Enable Auto-repair and JSON Lens fixes the common violations for you, showing exactly what it changed.

Common JSON errors and how to fix them
Error messageTypical causeFix
Expected property name or '}'Unquoted key, or single-quoted keyQuote the key with double quotes — or let Auto-repair do it
Unexpected token ' in JSONSingle-quoted stringConvert '…' to "…" (Auto-repair handles it)
Unexpected token } … at position NTrailing comma before } or ]Remove the comma; the caret in the error banner shows the spot
Unexpected end of JSON inputTruncated / half-pasted JSONCheck that all brackets are closed — copy the input again in full
Unexpected token \n … at line NRaw newline or tab inside a stringEscape it as \n / \t
Unexpected token N in JSONNaN, Infinity or undefined in the dataReplace with null (Auto-repair replaces them)
Looks fine but still failsSmart quotes “ ” ‘ ’ from Word/macOS, BOM, or invisible zero-width charactersAuto-repair normalizes them; paste as plain text
Multiple objects, one per lineThat's JSON Lines (NDJSON), not a single JSON valueAuto-repair wraps them into an array

JSON Lens shows the error's line and column, prints the offending line with a caret, and offers one-click repair.

Escaped JSON strings: why they exist and how to unescape them

An "escaped JSON string" is JSON wrapped as a string value — what you get from JSON.stringify(obj) inside another JSON, from logs, or from message queues:

"{\"name\":\"Alice\",\"tags\":[\"a\",\"b\"],\"ok\":true}"

Each inner quote is prefixed with \. To get real JSON back you must parse the string once. Common sources of escaped JSON:

  • Double-encoded APIs — a server stringifies an object, then stringifies the whole response again.
  • Log lines where the payload is stored as a string field.
  • Shell/curl output with escaped quotes.
  • URL-encoded (%7B%22a%22…) or Base64-encoded (eyJuYW1lIjo…) JSON in query strings and JWT-like tokens.

JSON Lens detects each layer automatically — quotes, \n/\" escapes, URL-encoding, Base64 — and unwraps multiple layers in one click. The Escape button does the reverse: it turns your JSON into a safely escaped string you can paste into code or another JSON document.

Escape sequences reference

SequenceMeaning
\"Double quote
\\Backslash
\/Forward slash (optional escape)
\n \r \tLine feed, carriage return, tab
\b \fBackspace, form feed
\uXXXXUnicode code point (4 hex digits), e.g. \u4e2d = 中
JSONPath quick reference

Type a JSONPath above the tree and press Run. Supported syntax:

ExpressionMeaning
$Root object
.key or ['key']Object member
[0], [-1]Array index (negative counts from the end)
[0,2]Multiple indexes
[1:4], [::2]Array slice with optional step
.*, [*]All members / items
..keyRecursive descent — every key at any depth
[?(@.price<10)]Filter: == != < <= > >=, e.g. [?(@.type=='a')], [?(@.active)]
$.store.book[*].author        // all authors
$..price                      // every "price" anywhere
$.items[?(@.qty >= 2 & @.id != 9)]

Results are listed under the tree — click one to jump to the node, or copy them all as a JSON array.

JSON ↔ JavaScript: stringify/parse gotchas
  • JSON.stringify drops undefined (object properties and array items), functions and symbols; it turns NaN/Infinity into null.
  • Date objects become ISO strings — parsing them back gives strings, not Dates.
  • BigInt throws. Work around it with a replacer (BigInt.prototype.toJSON or string conversion).
  • Circular references throw Converting circular structure to JSON — use a replacer that tracks seen objects.
  • Key order: objects preserve insertion order (integer-like keys first, ascending); parsing never reorders them beyond that rule.
  • JSON.parse loses number precision for very long numbers (9007199254740993 becomes …992) — handle IDs as strings server-side.
  • Duplicate keys: the last one silently wins.
  • -0, sparse arrays, and toJSON() side effects all surprise people; when debugging, prefer the tree view which shows exactly what was parsed.
Privacy & how JSON Lens works

Your data never leaves the browser. There is no backend: parsing, repair, unescaping, JSONPath queries and TS/Schema export all run as local JavaScript. The page has no external scripts, no cookies and no tracking of your input — you can safely paste API responses containing tokens (just remember the share link encodes data in the URL itself, so only share it intentionally).

Under the hood: input is parsed with the native JSON.parse for exact, spec-compliant validation. If it fails, a layered pipeline tries string-unescape (quotes → \n/\" → URL → Base64), then targeted repairs (quotes, commas, comments, literals), reporting every fix. The tree renders nodes lazily, so even large documents stay responsive — and above 2 MB live parsing switches to a manual Parse button.

FAQ

Quick answers about this JSON formatter and viewer.

Is my JSON data uploaded to a server?

No. All parsing, formatting, repair and querying happens locally in your browser with JavaScript. Your input never leaves your device — there is no backend at all.

How do I convert an escaped JSON string back to JSON?

Paste the escaped string and JSON Lens auto-detects it. You can also press the Unescape button. It strips wrapping quotes, resolves \n, \" and \\ sequences, and handles multi-layer escaping, URL-encoded and Base64-encoded JSON.

What kinds of broken JSON can auto-repair fix?

Single quotes, trailing commas, unquoted keys, // and /* */ comments, Python literals (True/False/None), NaN/Infinity, smart quotes copied from rich text, and JSON Lines (one object per line, wrapped into an array).

How can I query a value deep inside a large JSON?

Use the JSONPath bar above the tree. Examples: $.store.book[0].title, $..author, $.items[?(@.price<10)]. Matching nodes are highlighted and results can be copied as JSON.

Is there a size limit?

There is no hard limit. Inputs up to a few MB parse instantly; above 2 MB live parsing switches to a manual Parse button to keep the page responsive, and the tree lazily renders nodes only when you expand them.