json

FormatValidateConvert

In this section · 02 Read itViews

02 · Read it

Four ways to read a JSON document

Four ways to look at one document, what each is good at, and the folding, wrapping and node counts they share.

Guide 2 of 9 in Editor

A JSON document is one thing and there are four useful ways to look at it. The text is what you edit and what a diff is taken over. The tree is what you read when the nesting matters more than the punctuation. The table is what an array of records really is. The graph is the shape of the whole thing at a glance. Each pane picks its own view, which is why the editor shows two: text on one side and something structural on the other is the arrangement most work happens in.

Switching views never changes the document. It is the same characters underneath, presented differently, and a view that cannot draw says so rather than showing you a partial answer. Nothing here is a mode you can get stuck in: switch back and the text is exactly as you left it, caret included.

The status bar, and why it goes quiet

Input

{
  "order": "A-1042",
  "lines": [
    { "sku": "PEN-01", "qty": 2 },
    { "sku": "PAD-02", "qty": 5 }
  ],
  "paid": true
}

Do

  1. Paste the document into the left pane, which opens in Code.
  2. Look along the bottom: the size is there and the node count is not.
  3. Switch the right pane to Tree, and look again.

Result

10 nodes · depth 3

Try it in the editor →

The count along the bottom is the same field on both sides of this example, and the switch is what fills it. That is not a bug worth apologising for — it is the visible edge of a deliberate decision about when the document gets taken apart.

In Code, a valid document is checked and left as text; nothing walks it. Counting values and measuring depth means building the tree, which is work, and doing it on every keystroke of a large file to keep a number in the status bar current would be the wrong trade. So the field waits until a structural view has built the tree anyway, and then shows what that tree contains.

Once it is there it stays useful: it is the quickest confirmation that a paste arrived whole, the quickest way to see that a filter really did cut the document down, and the number to quote when something feels slow.

The Code view

Input

A config with three separate mistakes in it, pasted into the left pane.

Do

  1. Leave the pane in Code and read the underlines.

Result

All three are underlined at once, not just the first. The status bar names the first one and where it is; the rest are waiting under the cursor.

Code is the text itself, with syntax colouring, line numbers and the editing you would expect. It is where you type, and it is the only view that can show a document that does not parse — which is exactly when you need to see it.

Every error is underlined, not just the first. That matters more than it sounds: a parser stops at the first problem it cannot get past, so a tool that reports one error at a time turns a config with four mistakes into four rounds of fix-and-retry. The status bar names the first one and where it is, and the rest are marked in place, so one pass down the document fixes the lot.

The Tree view

Input

A document nested six levels deep, with one branch you care about.

Do

  1. Switch the pane to Tree and fold the branches you are not reading.

Result

One row per value, each foldable, with the path to the selected row along the top and a node count in the status bar.

The tree gives every value its own row, indented by how deeply it sits, with a fold control on every object and array. It is the view for reading an unfamiliar document, because you can close everything you are not interested in and the shape of what is left becomes obvious.

Along the top of the pane is the path to the selected row, as a trail you can step back along, with a control to copy that path as JSONPath or as JavaScript property access. Pasting the path into your own code is often the actual reason someone opened a document here, and copying it by hand out of a deep tree is exactly the kind of thing people get wrong.

The Table view and its export

An array of objects is a table, and the Table view shows it as one: a row per record, a column per key, and a badge on any cell holding an object or an array that you can drill into. It has enough to it — the column rules for ragged records, the breadcrumb back out, and an export that writes CSV, TSV or a Markdown table — that it has a page of its own, with a worked example of both exports printed exactly as they come out.

The Graph view

Input

A document whose shape — what contains what — is the thing you are trying to understand.

Do

  1. Switch the pane to Graph.

Result

Objects and arrays become boxes joined by their keys. Past about two thousand nodes the graph declines to draw and says so, because a hairball is not a view.

The graph draws objects and arrays as boxes joined by the keys that connect them. Where the tree answers what is in here, the graph answers how is this put together, which is the question you have about an API response you did not design.

It has a ceiling, and it tells you when it hits it. Past roughly two thousand nodes the picture stops being a diagram and becomes a hairball that takes a long time to lay out and teaches you nothing, so the view declines to draw and says why rather than grinding. On a document that size the tree, folded to a couple of levels, is the view that answers the same question.

Fold and expand to a level

Input

A deep document you want opened two levels and no further.

Do

  1. Open the ▾ beside Expand all, then choose Level 2.

Result

Every branch opens to that depth and everything below it closes. Tree and Graph share the control and the levels mean the same thing in both.

The ▾ beside Expand all opens Level 1, Level 2 and Level 3. Picking one opens every branch to that depth and closes everything below it, which is a different and usually better move than expanding everything and scrolling. Two levels of a large config is often the whole summary you wanted.

Tree and Graph share the control and the levels mean the same thing in both, so a depth you found useful in one carries over when you switch. It is also the fastest way to collapse a document you have been rummaging through back to something you can read.

Preview an image

Input

A record whose avatar field holds a URL ending in .png, or a data: URI.

Do

  1. In Tree, Table or Graph, hover the value.

Result

A preview opens beside it. A data: URI draws at once; a web address asks first, because fetching it would tell that server you are looking.

A value that looks like an image — a URL ending in an image extension, or a data: URI — previews on hover in the Tree, the Table and the Graph. It turns a column of opaque strings into something you can check at a glance, which is the difference between believing an export is right and seeing that it is.

A data: URI draws immediately, because everything needed is already in the document. A web address asks first, and that question is deliberate: fetching an image tells the server hosting it that you are looking at this document, and a tool that promises nothing leaves the tab should not quietly make a request on your behalf.

Two panes, two views

Each pane chooses its own view independently, and that is the point of having two. Text on the left and a tree on the right is the arrangement most editing happens in: you type in one and watch the structure change in the other. In Compare it is more often the same view on both sides, because you are reading two documents against each other rather than one document two ways.

A search marks its matches in whichever view a pane is showing, and so do the marks a comparison or a schema check leaves behind. Nothing is only visible in one view, so switching to read something differently never means losing the thing you were looking at.

Long lines, and reading text that will not fit

Minified JSON arrives as one enormous line, and a document with long string values is not much better. Code wraps rather than scrolling sideways forever, so a single-line document becomes a readable block instead of a horizontal ribbon you drag along. If what you actually want is the structure rather than the characters, pressing Format first, or simply switching to the tree, answers the question faster than any amount of scrolling.

The structural views have the same problem in a different shape: a value that is a paragraph long would stretch its row across the pane. They truncate it in the row and give you the whole thing when the row is selected, so the layout stays readable and nothing is hidden from you. That trade — show the shape, keep the detail one click away — is the rule the tree, the table and the graph all follow.

Which view for which job

Reading an unfamiliar document: the tree, folded to two levels, then open what looks interesting. Fixing something that will not parse: Code, because it is the only one that can show a broken document at all. Checking a list of records for a missing or wrong field: the Table, where a gap in a column is visible in a way it never is in a tree. Understanding the shape of an API response: the Graph, once, and then the tree for the details.

None of this is a setting you commit to. The views are one click apart, each pane remembers which one it was showing, and the document underneath them never changes — so the right habit is to switch freely rather than to pick a favourite and work around it.

Open the editor and try the views on your own document, or read The Table view and its export for the one with the most in it. To change what you are reading rather than just look at it, go on to Edit a document.