CalcCafe

YAML to JSON Schema

Convert any YAML document into a draft-07 JSON Schema that captures its types and structure.

Example

Input YAML:

name: app
version: 1
tags:
 - a
 - b

Output JSON Schema (draft-07):

{
 "$schema": "http://json-schema.org/draft-07/schema#",
 "type": "object",
 "properties": {
  "name": { "type": "string" },
  "version": { "type": "integer" },
  "tags": {
   "type": "array",
   "items": { "type": "string" }
  }
 },
 "required": ["name", "version", "tags"]
}

How it works

The YAML is parsed with js-yaml into a JavaScript value, then a recursive type inferencer walks it to emit a draft-07 JSON Schema. Object keys become properties marked required, and arrays infer a shared item schema (or anyOf when items differ).

Good to know

YAML to JSON Schema takes a sample YAML document and infers a draft-07 JSON Schema from it, mapping each value to a type: strings, integers vs. plain numbers, booleans, null, arrays, and nested objects. It is aimed at developers who want a quick schema skeleton for config files, API payloads, or CI/CD manifests without writing one by hand. Everything runs in your browser, so even sensitive config can be pasted safely.

Reach for it when you have a working example but no formal contract yet, for example bootstrapping validation for a Kubernetes-style values file, a GitHub Actions snippet, or an OpenAPI request body. Because the inferencer only sees the one example you paste, the generated schema describes that example exactly rather than the full range of valid inputs.

To read the output, treat the properties block as the shape of one object and the required array as "every key that appeared in your sample." Integers are detected separately from floats (1 becomes integer, 1.5 becomes number), a uniform array gets a single items schema, and a mixed-shape array gets an items.anyOf listing each distinct variant. Dates parsed by YAML are emitted as string with format: date-time.

A practical caveat: the tool treats your example as ground truth, so it tends to over-constrain. Before using the schema for validation, review it and loosen what is too strict, in particular:

Frequently asked questions

How are required fields decided?
Every key present in a YAML mapping is listed in that object's required array, since the inferencer only sees the example you provide. Remove keys from the generated schema if they are actually optional.
What happens with arrays that mix different shapes?
If all array elements infer to the same schema, a single items schema is emitted. When elements differ, the tool combines the distinct shapes into an items.anyOf list so each variant is described.
Is my data uploaded anywhere?
No — this tool runs entirely in your browser. Your input never leaves your device and it works offline once loaded.
Is it free?
Yes, completely free with no sign-up and no limits.

People also ask

What JSON Schema version does this tool output?
It emits draft-07 schemas, signaled by the "$schema": "http://json-schema.org/draft-07/schema#" line at the top of the output. If you need a different draft, you can adjust that identifier and any draft-specific keywords by hand.
Does it tell integers apart from decimal numbers?
Yes. A whole-number value like 1 is typed as "integer", while a value with a fractional part like 1.5 is typed as "number". This follows JSON Schema's distinction where integer is a stricter subset of number.
How are null values in YAML handled?
A null value (or an empty/tilde value in YAML) is inferred as { "type": "null" }. If a field can be either a value or null in practice, you would need to combine the types yourself, for example with anyOf or a type array.
Can it convert JSON Schema back into YAML?
No, this tool only goes one direction, from a YAML example to an inferred JSON Schema. It does not reverse the process or generate sample data from a schema.
What is the difference between a JSON Schema and just converting YAML to JSON?
Converting YAML to JSON produces the same data in a different format. A JSON Schema instead describes the structure and types of that data so it can be validated, documented, or used for autocompletion, without containing the actual values.
How does it handle an array where items have different shapes?
If every element infers to the same schema, it emits one shared items schema. If elements differ, it collects the distinct shapes into an items.anyOf list so each variant is represented.
Will the generated schema validate documents other than my example?
Only if those documents match the example's structure. Because the schema is inferred from a single sample and marks all present keys as required, you typically need to relax it before it accepts other valid inputs.
Does this tool support YAML anchors, aliases, or multiple documents?
It parses input with js-yaml and infers a schema from the resulting value, so anchors and aliases are resolved during parsing. It works on a single document; multi-document YAML streams separated by --- are not the intended input.

Related tools