@ark/json-schema

中文文档
0.0.13发布于 2026/10/21MITTypeScriptES Module构建来源已验证近 30 天下载 2.1万

@ark/json-schema is a package that allows converting from a JSON Schema schema to an ArkType Type. For example:

原始使用文档
文档目录3 节
  1. What is it?
  2. Extra Type Safety
  3. Limitations

@ark/json-schema

What is it?

@ark/json-schema is a package that allows converting from a JSON Schema schema to an ArkType Type. For example:

import { jsonSchemaToType } from "@ark/json-schema"

const T = jsonSchemaToType({ type: "string", minLength: 5, maxLength: 10 })

is equivalent to:

import { type } from "arktype"

const T = type("5<=string<=10")

This enables easy adoption of ArkType for people who currently have JSON Schema based runtime validation in their codebase.

If you want to convert your existing ArkType Types to JSON Schema, you don't need this library.

Instead, use the built-in toJsonSchema() method that exists on every Type, e.g.:

import { type } from "arktype"

// { type: "string", minLength: 5, maxLength: 10 }
const schema = type("5<=string<=10").toJsonSchema()

Extra Type Safety

If you wish to ensure that your JSON Schema schemas are valid, you can do this too! Simply import the relevant Schema type from @ark/json-schema like so:

import type { JsonSchema } from "arktype"

const integerSchema: JsonSchema.Numeric = {
    type: "integer",
    multipleOf: "3" // errors stating that 'multipleOf' must be a number
}

Note that for string schemas exclusively, you must import the schema type from @ark/json-schema instead of arktype. This is because @ark/json-schema doesn't yet support the format keyword whilst arktype does.

import type { StringSchema } from "@ark/json-schema"
const stringSchema: StringSchema = {
    type: "string",
    minLength: "3" // errors stating that 'minLength' must be a number
}

Limitations

  • No dependencies support
  • No if/else/then support
  • multipleOf only supports integers

版本与发布记录

@ark/json-schema 共发布 12 个版本,首次发布于 2025/04/07;过去 12 个月发布了 8 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.0.13latest2026/10/2118 天前
0.0.122026/10/0830 天前
0.0.112026/10/021 个月前
0.0.102026/10/011 个月前
0.0.92026/09/251 个月前
0.0.72026/07/084 个月前

关于 @ark/json-schema 的常见问题

@ark/json-schema 是什么?

@ark/json-schema is a package that allows converting from a JSON Schema schema to an ArkType Type. For example:

如何安装 @ark/json-schema?

在项目目录运行 npm install @ark/json-schema,或使用 pnpm add / yarn add / bun add。

@ark/json-schema 支持 TypeScript 吗?

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

@ark/json-schema 支持 ESM 还是 CommonJS?

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

@ark/json-schema 可以商用吗?

@ark/json-schema 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ark/json-schema 的下载量有多少?

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

@ark/json-schema 还在维护吗?

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