Skip to content

F06 — Schema Inference from Data Files ​

Overview ​

The extension can generate a draft JSON Schema from an existing JSON, JSONC, JSONL, or YAML data file using the genson-js library.

User Stories ​

  • As a developer starting from existing data, I want to generate a schema automatically rather than writing it from scratch.
  • As a team lead adopting schema-first workflows, I want a starting schema I can refine and commit alongside the data.

Functional Requirements ​

Command ​

  • F06-FR-01 The command jsonschema.inferSchema MUST be available in the Command Palette.
  • F06-FR-02 The Generate Schema toolbar icon (wand) MUST appear whenever jsonschema.isJsonSchema is false (data files, not schema files), regardless of whether the file already has a schema bound (inline $schema, a settings binding, or a natively-resolved schema per F04-FR-15). An earlier revision also hid the icon whenever any of those was present, on the theory that generating a schema from a file that already has one is pointless; in practice there is no reliable way to draw that line — an existing binding (of any kind, including a natively-resolved one like a Helm chart's values.schema.json) is not proof the user never wants to (re)generate a starting point from the file's current data — so the icon is never hidden on that basis.

Parsing ​

  • F06-FR-03 JSON files MUST be parsed with JSON.parse.
  • F06-FR-04 JSONC files MUST have comments stripped before parsing.
  • F06-FR-05 JSONL files MUST be parsed as an array (one JSON object per line).
  • F06-FR-06 YAML / YML files MUST be parsed with the yaml package.
  • F06-FR-07 A parse error MUST show an error notification with the error message and MUST NOT proceed.

Generation ​

  • F06-FR-08 The inferred schema MUST be produced by genson-js's createSchema function.
  • F06-FR-09 The generated schema MUST include "$schema": "http://json-schema.org/draft-07/schema#".
  • F06-FR-10 The generated schema MUST be pretty-printed (2-space indentation).

Output ​

  • F06-FR-11 The generated schema MUST be opened in a new untitled document with languageId: "json" in ViewColumn.Beside.
  • F06-FR-12 A notification MUST inform the user to save and bind the schema to use it for validation.

Semantic enrichment ​

  • F06-FR-13 After structural inference, the generator MUST run a deterministic enrichment pass over the observed values, adding a format to a string property when every observed value at that path matches one well-known format (email, uri, date-time, date, uuid, ipv4), and never when even one value does not. Structural inference alone says type: string for an e-mail address; the format is what makes the inferred schema catch a malformed one.
  • F06-FR-14 The pass MUST add an enum to a string property when the path has been observed enough times (at least 4) to make a closed set plausible, the distinct values are few (at most 5), and they repeat (distinct ÷ observed ≤ 0.5). It MUST NOT infer an enum from a single document, where every value is trivially unique — that would freeze first-seen data into a contract.
  • F06-FR-15 Enrichment MUST be additive and pure: it MUST NOT remove, rename or retype anything the structural pass produced, MUST produce identical output for identical input, and MUST be skippable (--plain in the CLI). The optional model-assisted pass (F32-FR-10) builds on this deterministic one, never replaces it.

Acceptance Criteria ​

  1. Running Generate Schema from This File on person-valid.json opens a new editor tab containing valid JSON with a $schema field and at least the top-level property types inferred from the data.
  2. Running the command on a malformed JSON file shows an error notification.

History ​

  • 2026-09-02 — Added F06-FR-13/14/15: a deterministic enrichment pass after structural inference — format when every observed value matches, enum when a path repeats a small closed set across enough observations. Additive, pure and skippable; the model-assisted pass in F32 builds on it rather than replacing it.

Requirement traceability ​

Status of each requirement in specs/traceability.json. Test coverage is auto-discovered from [ID] tags in test titles and is not listed here.

RequirementStatusImplementationNote
F06-FR-01implementedpackage.jsoninferSchema in commandPalette
F06-FR-02implementedpackage.json, src/SchemaBindingManager.tsinferSchema editor/title icon, gated only on !isJsonSchema; never hidden for an existing binding
F06-FR-03implementedsrc/extension.tsinferSchema: JSON.parse path (unit-tested)
F06-FR-04implementedsrc/extension.tsinferSchema: JSONC strip (unit-tested)
F06-FR-05implementedsrc/extension.tsinferSchema: JSONL array (unit-tested)
F06-FR-06implementedsrc/extension.tsinferSchema: YAML parse (unit-tested)
F06-FR-07implementedsrc/extension.tsinferSchema: parse-error notification (unit-tested)
F06-FR-08implementedsrc/extension.tsinferSchema: createSchema (unit-tested)
F06-FR-09implementedsrc/extension.tsinferSchema: draft-07 $schema (unit-tested)
F06-FR-10implementedsrc/extension.tsinferSchema: pretty-printed (unit-tested)
F06-FR-11implementedsrc/extension.tsinferSchema: opens json Beside (unit-tested)
F06-FR-12implementedsrc/extension.tsinferSchema: bind hint notification (unit-tested)
F06-FR-13implementedsrc/inferenceEnrich.ts, src/extension.ts, src/cli/cli.tsdeterministic format/enum enrichment after genson inference; pure, additive (property-tested), --plain in the CLI
F06-FR-14implementedsrc/inferenceEnrich.ts, src/extension.ts, src/cli/cli.tsdeterministic format/enum enrichment after genson inference; pure, additive (property-tested), --plain in the CLI
F06-FR-15implementedsrc/inferenceEnrich.ts, src/extension.ts, src/cli/cli.tsdeterministic format/enum enrichment after genson inference; pure, additive (property-tested), --plain in the CLI

Documented in ​

Documentation sections tagged spec:F06 (or one of its requirement ids) — 454 of ~518 expected words (88%). The expectation comes from this spec's evaluated complexity of 12.9 (15 documentable requirements — 15 FR — weighted by kind and by each definition's length).

Changes over time ​

  • d152a832026-09-02feat: finish the analysis follow-ups — inference enrichment, MCP distribution, quiet confirmations
  • 3a71cdc2026-07-23fix(binding): never hide the Generate Schema wand for an existing binding
  • 13edbff2026-07-16fix(binding): recognise auto bindings and refine schema affordances
  • ac906af2026-06-23docs(specs): add software requirements specification

Released under the MIT License.