YAML to JSONSchema

Infer a JSON Schema from a sample YAML document.

YAML to JSON Schema – Validation for configuration files

The YAML to JSON Schema generator infers a schema from a sample YAML document. JSON Schema is the standard way to validate YAML configuration: editors use it for autocompletion and inline errors, and CI jobs use it to reject broken config before deployment.

How the schema is inferred

The YAML is parsed with the YAML 1.2 core schema, anchors and aliases are resolved, and every value gets a schema: mappings become "type": "object" with properties, sequences become "type": "array" with an items schema, and scalars become integer, number, boolean, string or null. Objects inside a list are merged, so one schema covers every item, and keys that only occur in some items stay optional.

Options

Choose the draft (2020-12, 2019-09, draft-07 or draft-04) so the $schema URL and keywords match your validator. Mark keys required adds a required array, Allow additional properties controls whether unknown keys are accepted, and Detect formats adds format hints such as date-time, email, uri and uuid for matching strings.

Using the schema in your editor

Save the output as schema.json and reference it from the top of a YAML file with a # yaml-language-server: $schema=./schema.json comment, or map file patterns to it in your editor settings. You get completion of key names, hover documentation and red squiggles for wrong types.

Typical uses

Validating Helm values files, application config and feature flags in pull requests, documenting the shape of a config format for other teams, and bootstrapping a schema you will later refine with enum, minimum or pattern constraints.

Tips

A generated schema describes only the sample you give it. Add a few varied examples, then tighten the result by hand – for instance turn a string field with three known values into an enum.

Validate your input with the YAML Validator, convert it with YAML to JSON, or generate a schema from JSON with JSON to JSONSchema.

Frequently Asked Questions

Yes. A YAML document with plain mappings, lists and scalars has the same data model as JSON, so tools like the YAML extension for VS Code, check-jsonschema and ajv validate YAML against a JSON Schema directly.

Use 2020-12 for new projects. Pick draft-07 for editors and libraries that do not support newer drafts yet, and draft-04 only for legacy tooling such as old Swagger 2.0 validators.

With 'Mark keys required' enabled, a key is required only if it appears in every object of the same shape. Keys missing from some list items, or set to null, are left optional.

No. The schema is inferred locally in your browser, so internal configuration files stay private.