The JavaScript/TypeScript deserializer for AlchemyCMS's JSON:API.
npm install @alchemy_cms/json_api --saveor with the package manager of your choice.
deserialize converts a JSON:API response into plain, acyclic JS objects:
each resource's attributes are flattened with its id, and relationships
present in included become nested objects (absent ones become { id }
stubs). Reference cycles are broken automatically, so the result is always
safe to JSON.stringify.
import { deserialize } from "@alchemy_cms/json_api"
const response = await fetch("/jsonapi/pages/homepage.json")
const page = deserialize(await response.json())
console.log(page.name) // => "Homepage"deserializePage and deserializePages still exist as thin, deprecated
aliases for deserialize; prefer deserialize.
This package lives in the javascript/
directory of the alchemy-json_api monorepo. Releases are automated with
release-please and tagged package-vX.Y.Z.