"$schema" field in its default output. It is omitted from the examples below for readability.
Install
Basic usage
required alphabetically and does not add additionalProperties: false; you should add that manually.
Multiple instances
Genson’s strength is incremental learning. Feed it several examples and it merges them, detecting which fields are always present (required) and which appear only sometimes (optional):phone is missing from the second example, it becomes optional while name and email stay required.
Nested objects
Genson handles nested structures, inferring a full sub-schema for each nested object:$defs.
Arrays
Genson infers array item types from the elements it sees:minItems or maxItems; add those manually. See Bounded Arrays.
Arrays of objects
When arrays contain objects, Genson infers the item schema by merging all observed elements:Mixed types
When the same field has different types across samples, Genson produces a type union:Seeding with an existing schema
You can start from a hand-written schema and let Genson extend it with fields observed in data. Constraints from the seed schema (likeenum) are preserved:
enum constraint on category is preserved from the seed. summary is added to properties but not to required since it was not in the seed’s required list.
Limitations
Genson infers structure and types but does not add semantic constraints. The generated schema will not include:enumvalues (unless seeded)minLength,maxLength, orpatternfor stringsminItems,maxItemsfor arraysadditionalProperties: falseon objectsdescriptionon fields or the schema