What the JSON viewer does
A JSON viewer turns a block of JSON text into a tree you can open one level at a time, so you can find your way around an API response or a config file without reading every line. This one is also a JSON editor: you can change the data in the tree and copy or download the result.
- Tree view: each object shows how many keys it has and each array how many items, with a badge giving every value's type.
- Search: finds text in keys, values or both, highlights it in the tree and steps through the matches, opening any collapsed nodes on the way.
- Paths: gives the path to the selected value in two forms, ready to paste into a query or into code.
- Editing: rename keys, change values and types, delete nodes and add new keys or array items.
- Stats: the root type, the total number of keys, the nesting depth and the size of the text in bytes.
To indent, minify or validate JSON as text, or to see why a document fails to parse, use the JSON formatter. This viewer shows the same line and column for syntax errors. To compare two documents, use the JSON diff tool.
How paths are written
Every node has a path from the root. The viewer writes it two ways:
| Key | JSONPath | JavaScript |
|---|---|---|
name | $.name | data.name |
| Array item 0 | $[0] | data[0] |
post-code | $["post-code"] | data["post-code"] |
first name | $["first name"] | data["first name"] |
$id | $["$id"] | data.$id |
2024 (a key, not an index) | $["2024"] | data["2024"] |
JSONPath, standardized in RFC 9535, starts at $. The short .name form is only allowed when the name starts with an ASCII letter, underscore or any non-ASCII character, and continues with those or digits; anything else goes in brackets as a quoted string. In JavaScript, dot access works for any valid identifier, which includes names containing $, and bracket access with a string works for every key. The viewer uses data as the variable name, so replace it with your own. The viewer puts every key that is not a plain ASCII name in brackets, which is valid in both notations. A key containing a lone surrogate (half of an emoji or other character outside the Basic Multilingual Plane) cannot be written in JSONPath at all, so the viewer says so and gives only the JavaScript path.
How editing works
Each edit builds a new copy of the data with one change, then writes the whole document back into the input box: indented if your input was indented, minified if it was all on one line. The old copy is kept so Undo can restore it, up to the last 50 edits. Because the input box is rewritten, the text there always matches the tree, and the stats update after every change. Because the document is rebuilt from the parsed data, the first edit applies JavaScript's parsing rules to the whole file: integers above 9,007,199,254,740,991 are rounded, only the last of any duplicate keys is kept, keys that are array indexes such as "2" move to the front of their object, and numbers are rewritten in their shortest form, so 1.0 becomes 1 and 1e3 becomes 1000.
When you change a value, the type list decides how your text is read. A string is taken exactly as typed, without surrounding quotes. A number must follow JSON's number rules, so 1e3 and -0.5 work but .5, +1 and 1,000 do not. A boolean is true or false, and an object or array is entered as JSON, such as {"a": 1}. Renaming a key keeps it in the same position, unless the old or new name is an array index such as "2", which JavaScript always moves to the front.
Large files
The tree only creates page elements for nodes you can see. A collapsed object costs nothing to display however much it contains, and a large array shows its first 200 items with a button to show 200 more. Expand all stops at about 3,000 visible rows and says so, so a file of several megabytes stays usable. Search and stats still cover the whole document.
Opened files are read with the browser's FileReader and parsed with JSON.parse. Nothing is sent to a server. Your JSON and search text are never put in the page address or saved; only options such as the output indent are remembered.
Worked example
Click Load sample. The input holds a small bookshop record with 31 lines, and the stats read object, 17 keys, depth 4, 451 bytes. The key count includes keys in nested objects, and depth 4 is the path down to a tag such as "sci-fi": root, books, the first book, its tags array, then the tag.
Search for sci: there is 1 match, and Next opens the tree to $.books[0].tags[0]. Click the post-code key under address and the paths read $.address["post-code"] and data.address["post-code"], because a hyphen is not allowed in the short form.
Now make four edits: rename post-code to postcode, set the second book's year to the number 1816, add the string classic to its tags array, and delete manager. The second book becomes {"title":"Emma","year":1816,"tags":["romance","classic"]}, and the stats read 16 keys, depth 4, 450 bytes.
Common mistakes
- Typing quotes around a string value. With the type set to string,
"Ada"is stored with the quote marks as part of the text. TypeAda. - Numbers saved as strings. If the type is still string,
42is saved as"42". Pick number first. - Using a JavaScript path as JSONPath. They look alike, but JSONPath starts with
$, anddata.$idis valid JavaScript but not a JSONPath shorthand. - Editing a file with very large IDs. Numbers above 253 lose precision when the file is rewritten. Keep such IDs as strings, or edit the text directly. The JSON formatter explains this and other parsing edge cases.