All writing

November 21, 2026 · 10 min read

JSON:API is not JSON: resolving relationships you cannot see

A JSON:API document is a flat list of resources plus type/id pointers. Expanding one level of included looks correct and often isn't — what recursive resolution has to survive, which well-known APIs actually speak the format, and what it found in a real production response.

A JSON:API document parses as JSON, which is the root of most of the confusion. The shape is familiar — objects, arrays, strings — so people read it with a JSON mindset and conclude that a relationship pointing at { "type": "widgets", "id": "25676" } is somehow "resolved". It is not. That object is a pointer into a different part of the document, and if the resource it names is not there, the pointer is a dead end that still renders perfectly.

I built JSON:API Lens because I kept hitting this while debugging a storefront API. The document looked fine, the viewer showed a tidy tree, and the thing I actually needed — what is nested under this screen — was two includes away and silently absent.

The flat shape is the point

JSON:API splits a response into data (primary resources) and included (a flat list of every other resource the server decided to send). Relationships between them are resource linkage: a type/id pair, or an array of them, or null. Nothing is nested. A request like include=widgets.blocks.actions asks the server to append those resources to included — it does not ask it to build a tree.

That design is good. It avoids duplication, makes caching per resource possible, and keeps payloads predictable. It also means the tree you want exists only as an interpretation of pointers, and every tool that renders JSON:API has to make that interpretation explicitly — or quietly skip it.

Who actually uses it

This is not a niche format with one famous user. These are the apps and APIs built on it, in rough order of how likely an iOS engineer is to meet them:

  • App Store Connect. The one you will meet. Apple documents it as a REST API, but its published OpenAPI spec — App Store Connect API 4.6.1, 1,032 paths — is JSON:API shaped: resources carry type, id, attributes and relationships, and 341 of its response schemas have an included array. Builds, beta groups, beta testers, App Store versions and review submissions are all resources in that graph, which is why a release tool is really a relationship walker. It also shows the format in the wild: the spec defines no top-level jsonapi member, and responses are served as application/json rather than application/vnd.api+json — the most important API in the ecosystem is JSON:API shaped rather than strictly conformant.
  • Klaviyo. Rebuilt its public API on JSON:API in 2022 and wrote about the decision: includes and sparse fieldsets gave it the compound-query benefits it wanted without adopting GraphQL, and one envelope keeps 200+ endpoints consistent across teams. If you have ever received a marketing automation webhook, you have probably parsed this format.
  • Patreon. Its docs say it outright: "Our API follows the JSON:API spec." Their own documentation includes a hand-written loop that denormalizes included by following relationships — the exact walk this post is about, written out because the envelope is not going to do it for you.
  • Drupal. JSON:API ships in Drupal core, so a decoupled Drupal site returns it without a contributed module — it is a first-class, documented way to decouple a Drupal site.
  • Ember Data and DataCite. Ember Data's default adapter is JSONAPIAdapter; the format exists in large part because a frontend framework needed a standard for relational payloads. DataCite's DOI metadata API follows it too, which is a useful reminder that the format travels well beyond consumer apps — research infrastructure is one of its steadiest homes.
  • Zooniverse. The citizen-science platform's Panoptes API documents "JSON-API conventions" as its core model and ships official Python, JavaScript and Ruby clients. The apps you might recognise — Galaxy Zoo, Snapshot Serengeti — talk to the server through this same relationship graph, which is a reminder that the format is doing production work far outside commerce.

The contrast matters just as much. GitHub's REST API, Stripe and Shopify are not JSON:API; they each ship their own envelope. So a generic JSON viewer is the wrong tool for the APIs that do use it, and a JSON:API-specific one is wasted everywhere else. Knowing which is which is half the work.

One level of expansion looks like it worked

The easy implementation maps each relationship to a chip with the target's type and id, then lists included separately as "39 resources". Nothing is wrong on screen. But the question a developer opens the tool to answer is "what is under this thing", and that question is never answered at depth one. At depth one, every relationship on an included resource is still just a chip.

Going deeper is a graph walk, and a graph walk over user-supplied data has two failure modes that are easy to get wrong.

Failure one: identity

A resource's identity is type plus id — not id alone. widgets:25676 and blocks:25676 are different resources, and a map keyed by id alone will happily return the wrong one. Client-generated resources use lid instead of id, so identity has to fall through to type:lid:… rather than producing widgets:undefined for every one of them.

Failure two: cycles, and why "visited" is the wrong guard

Real graphs contain cycles: a block points at an action that points back at the block. Recursion without a guard never returns. The reflex is a global visited set, and it is wrong in a subtler way than the crash: a resource reachable through two different paths is not a cycle, but a global visited set will refuse to render it the second time and the tree will silently lose a branch.

The guard has to be per path, not per document. Each recursion carries the set of ancestors on the current path; a target already in that set is a cycle, and a target in the document but not on the path expands normally.

resolve(resource, ancestors):
    next = ancestors + resource.key

    for each relationship pointer:
        target = document.get(type + ":" + id)
        if target is null:          → missing (sparse linkage)
        if target.key in next:      → cycle (stop here, say so)
        else:                       → resolve(target, next)

The distinction matters on screen, because the two outcomes mean different things. A cycle is correct data that must not be expanded further. A missing target is data that was not sent. Both get an explicit card with the linkage pointer that led there — the anchor back to the raw document, so the reader can check the claim instead of trusting the tree.

Missing linkage is normal, not broken

In the production response I verified against, 19 unique targets could not be resolved. None of them was a server bug: they were stores and screen-revisions resources that the request never asked for in include. The spec calls this sparse linkage, and it is the common case. A viewer that hides unresolved pointers is not simplifying — it is removing the evidence that something was not requested.

The related check is full linkage: every resource in included must be reachable from primary data. An included resource nothing points at is a violation, and my verified response had zero of them. It is the kind of thing that is invisible in a flat list and obvious once you build the graph: orphans are rendered in their own section with an unlinked badge.

Projection: turning the envelope into plain JSON

Once the graph resolves, projecting a resource into ordinary nested JSON is the useful payoff — attributes flattened onto the resource, relationship names holding resolved objects instead of pointers. Three rules keep it honest, because a projection that loses information is worse than no projection:

  • Unresolved pointers stay visible. They become { "type": "stores", "id": "9", "_missing": true }, not null.
  • Cycles stop with a marker. _cycle: true, so a consumer can tell a repeat from an empty relationship.
  • Name collisions are preserved. If a relationship shares a name with an attribute, the relationship moves under _relationships instead of overwriting the attribute.

There is a budget as well — 5,000 resources, then _truncated: true. Without it, copying a resource from a 100,000-resource document is a good way to hang the tab.

Scale is a rendering problem, not a parsing problem

The parser and model builder are linear; the DOM is what breaks. Measured in headless Chrome on a local server:

10,000 resources    2.4 MB     ~0.5 s
100,000 resources   24.4 MB    ~3.4 s     ~190 MB heap
200,000 resources   49.3 MB    ~13 s      ~340 MB heap
400,000 resources   99 MB      —          refused before parsing

So the guards are all in the rendering layer: a 50 MB input cap with a notice instead of a frozen tab, primary cards in pages of 200, validation issues paged by severity with "copy all", the JSON tab dropping to plain text above 1.2 MB, and a graph capped at 400 nodes with the extra edges summarized in the toolbar. Up to about 10 MB the tool feels instant; around 25 MB it is comfortable; 50 MB is usable and slow, which is the honest description.

What it found in a real response

I verified the whole pipeline against a production storefront API — a legacy endpoint returning application/vnd.api+json:

  • 28,788 bytes, HTTP 200, 0 spec violations against JSON:API 1.1.
  • 1 primary screens resource, 39 included resources, 59 linkages, 4 types.
  • A four-level chain resolved correctly: screens #1685 → widgets #25676 → blocks #92683 → actions #93027.
  • All 31 actions resolved under their blocks; 19 sparse targets reported as missing.
  • Graph: 40 resolved nodes, 39 edges, 0 orphans.

That last line is the one I care about. A flat list of 39 resources tells you nothing about whether the data is shaped correctly; the graph makes an unlinked resource and an unrequested one two different, visible findings.

No dependencies, deliberately

The whole tool is about 4,700 lines of dependency-free JavaScript — parser, model, tree, graph, UI — with 33 core tests and 5 tree tests. A debugging instrument that needs a build step and a package tree is harder to trust than the thing it is debugging, and harder to keep running two years later. Static files, no runtime dependencies, and the validator follows the spec's own pointers so a failed check links to the exact member it is complaining about.

Try it on your own payload: the viewer, or read the shorter guides on relationships and included resources and the JSON:API 1.1 validator. The source is on GitHub.