@alchemy_cms/json_api

中文文档
5.0.0发布于 2026/10/16BSD-3-ClauseTypeScriptES Module零依赖构建来源已验证近 30 天下载 5587

JSON API deserializer for AlchemyCMS

原始使用文档
文档目录3 节
  1. Installation
  2. Usage
  3. Contributing

@alchemy_cms/json_api

The JavaScript/TypeScript deserializer for AlchemyCMS's JSON:API.

Installation

npm install @alchemy_cms/json_api --save

or with the package manager of your choice.

Usage

deserialize converts a JSON:API response into plain JS objects: each resource's attributes are flattened with its id, and relationships present in included become nested objects (absent ones become { id } stubs).

Each included resource is materialized once and shared by every reference to it, so the result stays proportional to the size of the response even when resources reference each other heavily. A consequence is that back-references (e.g. a menu node's parent, which lists the node among its children) are real references, and the result may contain cycles:

  • structuredClone, devalue (Nuxt payloads) and Vue/React state handle this fine.
  • JSON.stringify does not. If you need JSON, serialize a projection of the fields you need, or use a cycle-aware serializer.
  • Mutating a resource is visible everywhere it is referenced. Copy before mutating.
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.

Contributing

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.

版本与发布记录

@alchemy_cms/json_api 共发布 11 个版本,首次发布于 2022/09/07;过去 12 个月发布了 2 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
5.0.0latest2026/10/1622 天前
4.0.02026/09/022 个月前
3.0.12025/09/231.1 年前
3.0.02025/06/181.4 年前
2.0.02024/11/152 年前
1.3.02024/11/082 年前

关于 @alchemy_cms/json_api 的常见问题

@alchemy_cms/json_api 是什么?

JSON API deserializer for AlchemyCMS

如何安装 @alchemy_cms/json_api?

在项目目录运行 npm install @alchemy_cms/json_api,或使用 pnpm add / yarn add / bun add。

@alchemy_cms/json_api 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@alchemy_cms/json_api 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@alchemy_cms/json_api 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.19.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@alchemy_cms/json_api 可以商用吗?

@alchemy_cms/json_api 使用 BSD-3-Clause 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。另外不得用原作者名义为衍生产品背书。以上为概括,不构成法律意见,请以许可原文为准。

@alchemy_cms/json_api 的下载量有多少?

根据 npm 官方下载统计,@alchemy_cms/json_api 在 2026/10/06 – 2026/11/04 这 30 天内被下载 5,587 次,日均约 186 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@alchemy_cms/json_api 还在维护吗?

最新版本 5.0.0 发布于 2026/10/16(22 天前);至今共发布 11 个版本,其中过去 12 个月发布了 2 个;首次发布于 2022/09/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。