# JSON Schema Inferrer
Infer a draft-07 JSON Schema from a sample document. Pure stdlib.
```
python scripts/run.py sample.json
echo '{"id":1,"tags":["a","b"]}' | python scripts/run.py -
python scripts/run.py sample.json --title User
python scripts/run.py sample.json --no-required
```
Recursively types objects, arrays, and scalars; merges heterogeneous arrays.
---
name: json-schema-inferrer
display_name: JSON Schema Inferrer
description: "Infer a draft-07 JSON Schema from a sample JSON document, recursively typing objects, arrays, and scalars with required keys. Triggers: infer json schema, generate schema, json to schema, draft-07 schema from sample."
---
# JSON Schema Inferrer
Generate a draft-07 JSON Schema from an example JSON document.
## When to use
The user has a sample JSON payload and wants a schema describing its structure — types of every field, array item types, and which keys are required.
## How to use
Run `scripts/run.py` on a file or stdin:
- `python scripts/run.py sample.json` — print the inferred schema.
- `echo '{"id":1,"tags":["a","b"]}' | python scripts/run.py -` — infer from stdin.
- `python scripts/run.py sample.json --title User` — add a schema title.
- `python scripts/run.py sample.json --no-required` — omit `required` arrays.
Objects list all keys as `required` (unless `--no-required`); arrays infer a single merged `items` schema across all elements; mixed scalar types become an `anyOf` union.
## Pitfalls
- The schema reflects only the sample provided — fields absent from the sample won't appear.
- Heterogeneous arrays are merged into one item schema (objects union their properties, scalars become `anyOf`), not a positional tuple.
- Integers vs floats are distinguished (`integer` vs `number`); `1.0` infers as `number`.
JSON Schema Inferrer by langbot-team
Infer a draft-07 JSON Schema from a sample JSON document, recursively typing objects, arrays, and scalars with required keys.
Loading...