JSON Parser

Paste raw JSON, a quoted string from a log, or a value with backslashes in front of every quote. The parser peels each layer, draws the result as a tree, and points at the exact character when the text breaks.

  1. WaitingPaste text or press Load sample

Input text

0 B

The tree shows up here. Click any row to get its path.

Root
none
Depth
0
Keys
0
Strings
0
Numbers
0
Booleans
0
Nulls
0
Output
0 B

Two passes on one feedback event

Press Load sample. The box fills with a page feedback event the way a queue worker stored the event in Redis: encoded to JSON, then encoded a second time as a string. Every inner quote carries a backslash. JSON.parse on this text returns a string, not an object, and most parsers stop right there.

  1. 1
    Input, 400 bytes. The text opens with "{\"event\". The outer double quotes mark one long JSON string.
  2. 2
    Pass 1 returns a string of 356 characters. The backslashes are gone. The content starts with {, so the parser runs again.
  3. 3
    Pass 2 returns an object with 10 keys. The tree lists event, visitor, tags and the rest. Click name under visitor and the path bar reads $.visitor.name.

One line turns yellow under the stats. message_id holds 1847390012345678912, nineteen digits. A JavaScript number keeps about 16 digits exact, so the parsed value becomes 1847390012345678800. The warning names the path. Store ids like this as strings at the source, since every JavaScript consumer of the payload rounds the number the same way.

Turn off Unwrap string layers to see the raw first pass. The tree shows one string node, which is what JSON.parse alone gives your code.

Why this page never calls eval

The older version of this tool ran pasted text through eval() to strip the outer quotes. eval executes JavaScript. Paste a string holding a function call and the browser runs the call. A parser has no reason to execute anything.

The rebuilt page uses JSON.parse only. Each extra pass runs JSON.parse on the string the last pass returned, and only when the string starts with {, [ or ". A string such as "42" stays a string. Converting the value to the number 42 changes the type your code receives.

Some logs drop the outer quotes and keep the backslashes, as in {\"rating\":4}. The parser tries wrapping that text in quotes once. The first chip in the pass strip reads Bare escaped text when this happened.

Error messages, read in plain terms

Browsers word JSON.parse errors differently, and some leave out the position. This page runs its own scanner after a failed parse, so the message, line and column stay the same in every browser. A caret marks the character under the snippet.

MessageTypical sourceFix
Trailing comma before }A config file edited by hand, last line deletedRemove the comma after the final value
Property names need double quotesA JavaScript object literal pasted as JSONQuote every key: "rating": 4
Single quotes are not JSONPython print() of a dictUse json.dumps() on the Python side
Comments are not allowedtsconfig.json or a VS Code settings fileDelete the comment lines, or read the file as JSONC
NaN is not a JSON valueA division by zero serialized by a lenient librarySend null or a string
Raw line break inside a stringA multi-line message copied from a terminalEscape breaks as \n
Extra text after the JSON value endsNDJSON, one object per lineParse each line on its own

Several mistakes in one file? The scanner stops at the first. Fix the first error, and the next one shows. For bulk repairs of quotes and commas, the JSON Parser rewrites the text. This page reports and leaves the text alone.

Click a value, paste its path into code

Every row in the tree gives two paths. The JSONPath form, $.tags[1], goes into jq filters, Postman tests, or the JSONPath Tester. The JavaScript form, data.tags[1], goes straight after the variable holding the parsed result.

Keys with a dash, a space or a leading digit switch to bracket notation. A key named country-code prints as $['country-code'] and data["country-code"]. Dot notation there would read as a subtraction.

Where the parser stops

  • Strict JSON only. No comments, trailing commas, single quotes or unquoted keys. JSON5 and JSONC files fail on purpose, with the reason shown.
  • Long integers lose digits. Anything past 9,007,199,254,740,991 rounds. The warning lists up to five paths.
  • Duplicate keys keep the last value. {"id":1,"id":2} parses to {"id":2}. The warning list names the duplicated key, since the tree shows only the survivor.
  • Unwrapping stops after ten passes. Real data rarely goes past three. More than ten points at a loop in the code writing the value.
  • Big input waits for a click. Past one million characters, parsing on each keystroke pauses. Press Parse or Ctrl + Enter. Files above 20 MB are refused.
  • Large containers open in pages. The tree renders 500 children per object or array, with a button for the next 500. The Formatted tab always holds the full document.
  • Nothing leaves the tab. Parsing, the tree, copy and download all run in your browser.

Parser, Stringify or Beautifier?

You have a string

Escaped, quoted, or straight out of a log. You want the object. Stay here.

You have an object

You want the object inside a string literal for code or a test fixture. Use JSON Stringify.

You have clean JSON

You want indentation with every digit kept as typed. Use the JSON Beautifier.

JSON parsing questions

Strings inside strings, changed numbers, rejected files.

What does a JSON parser do?

A JSON parser reads JSON text and builds the data structure the text describes: objects, arrays, strings, numbers, booleans and null. In JavaScript the built-in parser is JSON.parse. This page runs JSON.parse, then shows the result as a tree with paths.

Why does JSON.parse return a string instead of an object?

The JSON was encoded twice. The text is a JSON string whose content is more JSON. Call JSON.parse a second time on the result. Leave Unwrap string layers on here and the page runs the extra passes for you.

How do I parse JSON with backslashes in front of every quote?

Paste the text as is. With outer quotes, pass 1 removes the backslashes. Without outer quotes, the parser wraps the text in quotes once, then parses the result.

Does the parser accept comments or trailing commas?

No. Comments, trailing commas and single quotes belong to JSON5 or JSONC, not JSON. The error shows the line, column and reason. Run the text through the JSON Fixer first.

Why did a long number change after parsing?

JavaScript numbers hold integers exactly only up to 9,007,199,254,740,991. Longer integers round to the nearest value the format stores. The yellow warning lists each affected path. Keep such ids as strings.

Is my JSON uploaded?

No. Files open through the browser file reader, and every pass runs in the page. Nothing reaches a server.