---
name: json-schema-builder
description: Generate a valid JSON Schema from example data, with nullability and enum detection baked in.
title: JSON Schema Builder
category: data-parsing
difficulty: intermediate
license: MIT
author: admin
source_url: "https://github.com/wolverdude/GenSON"
icon: 🧬
input: structured-data
output: structured-json
phase: transform
domain: data
tags: json-schema,schema-inference,data-extraction,type-detection,nullable-fields,enum-detection,code-generation,validation,llm-descriptions,nested-objects,cardinality-analysis,draft-2020-12
best_for:
  - API contract generation from example payloads
  - Data validation ruleset authoring
  - Self-documenting schema bootstrapping
  - Legacy database migration planning
---

## Description

Packaged skill that infers a JSON Schema (Draft 2020-12) from a folder of example documents. Detects nullable fields, enum-able strings (low cardinality), required vs optional, and emits a schema with human-readable descriptions derived from field names.

## Why it works

Hand-writing schemas is tedious and error-prone; the examples already contain the structural truth, they just need aggregation. Inferring nullability across N examples (rather than one) prevents the classic mistake of typing a field as `string` when 3% of your real data has it as `null`. Pairing inference with LLM-generated descriptions turns a dry schema into documentation that explains itself to downstream consumers.

## How it works

1) Parse every example file, recursing into nested objects/arrays. 2) For each field path, collect the set of observed types. 3) If more than one type appears and `null` is one of them, emit `oneOf: [<T>, null]`. 4) For string fields with ≤ 12 unique values across examples, emit an `enum`. 5) For numeric fields, emit `minimum`/`maximum` pulled from observed range. 6) LLM pass: generate a one-line `description` per field name using the field path + 3 sample values. 7) Validate the emitted schema against the original examples; any failure triggers a second pass that widens the constraint.
