JSON Schema validation in Node.js core
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.4k
- 平均合并
- 4 天 3 小时
- 30 天内合并 PR
- 272
描述
What is the problem this feature will solve?
Hi all,
I wanted to open a discussion about whether JSON Schema validation could be a useful addition to Node.js core.
Current state
- Node.js currently has no built-in JSON Schema validation
node.config.json(experimental) uses hand-written type checking against a JSON Schema 2020-12 definition generated from C++ option metadatapackage.jsonparsing uses simdjson but has no schema validation, fields are extracted structurally- The only schema validation in the Node.js tree lives inside
deps/npm(Ajv)
Potential use cases
- Validate
node.config.jsonagainst its own schema properly - Future validation for
package.jsonfields (opt-in, non-breaking) - Expose as a built-in module (
node:jsonschema) so userland doesn't need to pull in external validators
Context
I've been working on a project in this area, ata-validator, a JSON Schema validator built on simdjson and RE2. It currently passes 96.9% of the official JSON Schema Test Suite (Draft 2020-12) and falls back to a pure JS engine when native bindings aren't available.
I'm not proposing to land it as-is, I'd love to hear from the group first:
- Is there interest in having JSON Schema validation available in core?
- What would be the most useful entry point? (config validation, public API, both?)
- Any concerns about the dependency story? (RE2/abseil weight, simdjson already in core)
Happy to share benchmarks or more details if this sounds worth exploring.
fyi @Qard
What is the feature you are proposing to solve the problem?
A built-in JSON Schema validator, potentially exposed as node:jsonschema, that could also be used internally for validating node.config.json and other configuration files.
This would provide Node.js users with a fast, native JSON Schema (Draft 2020-12) validation capability without needing external dependencies.
What alternatives have you considered?
-
Continuing with hand-written validation for each config format individually,
doesn't scale as more config formats are added -
Bundling an existing JS-based validator like Ajv into core, lacks native performance benefits
-
Leaving JSON Schema validation entirely to userland
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先阅读 node.config.json 的验证路径、根据 C++ 选项元数据生成的 JSON Schema 2020-12 定义,以及 deps/npm 中的 schema 验证代码。将建议的 node:jsonschema、config-validation 和 package.json 入口点与现有的 Ajv 使用方式进行比较。在能够定义实现之前,需要先就范围和依赖策略达成一致,之后才算完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, node.js
- 领域
- backend
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 冷清
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100