0026 — jlens-schema reads JSON Schema itself, into shapes, and infers its own
Status: Accepted. Recorded in 0.34, after the fact: the reader and the inference date from
the first jlens-schema (October 2026), and the references grew in 0.33
(ADR 0024, ADR 0025).
Context
jlens-schema does two things with JSON Schema. It infers a schema from sample documents
(Schema::infer, jlens schema infer), and it reads one, inferred, written by hand or
generated by another tool, for the language service: completion, hover, the diagnostics, the
type of the result and what an expression uses. Rust has mature JSON Schema crates, and
ADR 0001 only covers implementing JSONata itself. So the question
is whether jlens reinvents them.
What the language service needs from a schema is not what a validator gives:
- A query without a document. The typing asks, for a path that an expression builds, which
fields and which types a value can have there. No document is at hand when someone types
customer.in an editor. The load therefore turns the schema intoSchema, a tree ofShapes (types, fields withrequiredor their presence, items,enum,format, ranges, descriptions, the fields an object leaves open, references by name to definitions), whichSchema::shape_atand the typing walk. - A reading that keeps the warnings sound. A warning says that the schema does not allow
something, so a keyword that allows more must be read, and one that only narrows may be left
out. The schema guide classifies every keyword of JSON Schema 2020-12, the drafts before it
and OpenAPI 3.0 that way (the keywords jlens reads):
read, left out because it only narrows or only describes, or reported. A reported keyword
(
$dynamicRef,$recursiveRef, atypethat names no JSON type) leaves its place unknown, and the load lists it beside the schema. - Combinators read as sets of values.
allOfis merged into one shape. Roadmap 0.34 #11 readsanyOfandoneOfas one branch or another: a field is required only where every branch requires it, and a branch that gives no type leaves the type unknown. A validator needs neither: it checks each branch against the document. - A load that does not fail. A
$refthat cannot be followed leaves its place unknown and is reported with its place (ADR 0025), and the load is bounded by the size of its documents, whoever wrote them.
Inference has needs of its own. It records more than the schema a GenSON-style tool writes
(types, properties, required, items): the fraction of objects that had a field that is not
required (x-jlens-presence), string formats, number ranges, small enumerations
(x-jlens-enum-inferred), minItems: 1 for arrays never seen empty
(x-jlens-min-items-inferred) and examples. It observes samples into the same Shape the load
builds, so an inferred schema, written and read again, answers the same.
The crates checked
On crates.io, on 2026-11-12. “Last release” is the date of the version given.
| Crate | Version, last release | What it is | Why it does not serve |
|---|---|---|---|
jsonschema | 0.61.2, 2026-11-12 | The most used validator. Compiles a schema into a Validator; validates documents, with errors and the annotations of the Output v1 format; fetches remote references, bundles and dereferences schemas, validates against meta-schemas | Its questions are about a document. A compiled Validator exposes checks, not the fields and types of a place |
referencing | 0.61.2, 2026-11-12 | The resolver of jsonschema, from the same repository: a Registry of documents by URI, a Resolver that looks up a reference, per-draft rules, the dynamic scope of $dynamicRef, a Retrieve trait for documents not given | It could have served the resolution: see below |
boon | 0.6.1, 2025-01-07 | A validator, drafts 4 to 2020-12; passes the JSON-Schema-Test-Suite but its optional cases; errors as a hierarchy | As jsonschema |
valico | 4.0.0, 2023-05-13 | A validator and coercer, draft 7; no repository named on crates.io | As jsonschema, and no release since 2023 |
jsonschema-valid | 0.5.2, 2023-11-08 | A validator, drafts 4, 6 and 7 | As jsonschema, and no 2019-09 or 2020-12 |
json_schema_ast | 0.6.0, 2026-11-12 | Builds, validates and resolves 2020-12 schemas and OpenAPI 3.1 Schema Objects, with a resolved graph that can be walked; the front end of jsoncompat | The closest to a static reader, but its README rejects the other drafts named by $schema, does not read OpenAPI 3.0’s nullable, and rejects plain-name fragments ($anchor), dynamic references, and remote ones not registered beforehand. It has no notion of a keyword that only narrows |
jsonschema-schema | 0.2.0, 2026-03-06 | Typed structs for the keywords of 2020-12, with navigate_pointer, which follows $ref | A typed parse of the keywords, not a reading of them: what each means for a place would remain jlens’s |
unbinder | 0.2.0, 2026-10-14 | Replaces each $ref by its target, bounded by depth, size and document limits; Documents lists the documents still missing and opens none; a cycle is left as $ref and listed | Its output is a schema again, which jlens would still read, and a cycle left as $ref would still be jlens’s to resolve. Its $ids follow json-schema-ref-parser, counting only where the root has one or names a draft, and its README does not mention $anchor |
schemars | 1.2.3, 2026-10-12 | A schema from Rust types (#[derive(JsonSchema)]) | The other direction |
typify | 0.8.0, 2026-09-09 (0.10.0-alpha.3, 2026-10-14) | Rust types from a schema, as source code at build time | The other end of the same problem: its README calls JSON Schema “a constraint language designed for validation”, which it reads as one interpretation into Rust types. jlens needs the reading at run time, as data, and keeps what it cannot read unknown |
genson-rs | 0.2.0, 2024-05-26 | A fast port of GenSON: a schema (draft-04 and later) inferred from documents | The GenSON schema, without the presence, formats, ranges, enumerations and minItems above. No release since 2024 |
genson-core | 1.4.0, 2026-10-26 | A vendored and extended genson-rs, with normalisation to Avro and Parquet schemas | As genson-rs; its additions are for data pipelines |
json-schema-profiler | 0.0.1, 2026-10-25 | Counts, at each path of a set of documents, how often a field is present and of which type, then proposes a schema under a strict or an expansive policy | The nearest to jlens’s inference, but experimental, and released after it |
The options
- Build on a validator (
jsonschema,boon). A compiled validator holds checks run against a document, and gives no way to ask what a place may hold. jlens would walk the schema’s JSON itself all the same, and carry a validator it never runs. - Build on a static reading (
json_schema_ast,jsonschema-schema,typify’s type space). These read a schema without a document, but each covers fewer drafts or dialects than jlens reads, or ends in Rust source. None tells a keyword that widens from one that narrows, and none leaves a place unknown and reports why. The rules of the guide’s table would be written over them all the same. - Read the schema ourselves, from its JSON values, possibly taking the resolution of
$reffromreferencing.
Where reuse was possible: referencing
The step from the text of a $ref to its target is the same for a validator and for jlens.
referencing does what decision 2 of ADR 0025 describes (base URIs from $id, anchors, JSON
Pointers), and more: the rules of each draft, such as draft-04’s id, and the dynamic scope
that $dynamicRef and $recursiveRef need, which jlens reports instead of reading. It is
maintained and widely used. jlens kept its own resolver, uri.rs (RFC 3986, section 5.2, in
about 330 lines with their tests) and the index of $ids and $anchors in the load, because:
- The part it would replace is small, and the rest stays. What ADR 0024 and ADR 0025 decide
is about the walk over the schema: the
$refs that lead back to themselves, found as the strongly connected components of the graph of references, become references by name; the budget counts the values each target would copy before any is copied; the report gives the place of each$refnot followed.referencingresolves a reference given to it, so all of that would remain. - Its failures are not jlens’s. Its README says that it resolves every external reference
eagerly, and
RegistryBuilder::preparefails when a retrieval fails. jlens loads the schema without the document, leaves each place that needs it unknown and lists them, and the CLI asks for the documents and loads again (load_asking). ARetrievethat records what it was asked and returns a placeholder could imitate that, but the placeholder would be read as a schema. - Its dependencies.
referencing0.61.2 bringsahash,fluent-uri,getrandom,micromap,parking_lotandpercent-encoding, none of which jlens builds today:jlens-schemaadds nothing to what the evaluator already depends on. The WebAssembly package, which buildsjlens-schema, has a size budget, and the C API ships it in every library of the Java package.
What would change this: reading $dynamicRef and $recursiveRef instead of reporting them,
or reading draft-04’s id. Their scope is what referencing already implements, and writing
it again would be reinventing it. Then referencing would be weighed again, for the step from
the text to the target only, under the walk, the budget and the report.
Decision
jlens-schema reads JSON Schema itself: the load walks the schema’s JSON values, resolves
$ref with its own URI resolver, and builds Shapes, following the keyword classification of
the schema guide. Inference is its own as well, and observes samples into the same shapes.
jlens does not validate documents against a schema. An application that needs validation uses a validator crate beside jlens, which neither competes with it nor wraps it.
Consequences
- jlens owns the classification of the keywords, and keeps it current: a new draft or dialect is a change to the guide’s table and to the load, and until then its new keywords are not read.
- The resolution of
$ref,$idand$anchoris tested by jlens’s own tests only. The official JSON-Schema-Test-Suite could test it: the schemas of its reference cases (such asref.json,refRemote.jsonandanchor.json), with the documents of itsremotesfolder given by URI, should load with every$reffollowed, and the shape of a place should hold its valid documents. This is a possibility, not a plan. jlens-schemahas no dependency on a validator or a resolver: its dependencies are those of the evaluator.- When
referencinggains what jlens would otherwise write (above), this ADR is to be revisited, not extended in place: a later ADR supersedes it.