nodejs / nodejs/node

JSON Schema validation in Node.js core

Offen
#62,598 26 Kommentare 61 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

feature request
Vorherrschende Sprache
JavaScript
Sterne
122k
Forks
37.3k
Ø Merge
4 T. 2 Std.
Gemergte PRs (30 T.)
283

Beschreibung

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 metadata
  • package.json parsing 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.json against its own schema properly
  • Future validation for package.json fields (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:

  1. Is there interest in having JSON Schema validation available in core?
  2. What would be the most useful entry point? (config validation, public API, both?)
  3. 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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, den Validierungspfad von node.config.json, die Definition von JSON Schema 2020-12 aus den C++-Optionsmetadaten und den Schema-Validierungscode in deps/npm zu lesen. Vergleiche die vorgeschlagenen Einstiegspunkte node:jsonschema, config-validation und package.json mit der bestehenden Ajv-Verwendung. Als abgeschlossen gilt dies erst, wenn ein vereinbarter Umfang und eine Abhängigkeitsstrategie feststehen, bevor die Implementierung definiert werden kann.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, node.js
Bereich
backend
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Ruhig
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.