JSON Schema from samples: infer draft 2020-12 and validate data
Infer a draft 2020-12 JSON Schema from sample JSON or JSON Lines, with required fields, enums and formats, and validate data with a built-in minimal validator.
What it does
Turn undocumented JSON (API responses, configs, exports) into a draft schema and check that data matches it.
- Merges every sample to determine types, nullability, required vs optional properties and array item types (for example, a field present in 23 of 45 objects is optional)
- Emits enums for strings with few distinct values, and formats (
date-time,date,time,email,uuid,ipv4,ipv6,uri) only when every value matches - Notes optional and mixed-type fields, and self-checks that all samples validate against the inferred schema
- Validates other data with a built-in validator and prints errors as
file:line /json/pointer: reason - Optional
--bounds(observed min/max) and--strict(no additional properties)
How to use
python scripts/json_schema_tool.py infer samples/*.json --out schema.json --title Order
python scripts/json_schema_tool.py validate --schema schema.json new-batch.jsonl
Ask Claude, Codex, Hermes Agent or Cursor to "write a JSON Schema for this data"; it infers the schema, then reviews required fields and enums with you before finalizing.
Requirements
- Python 3.10+ (standard library only)
Caveats
- Inference only knows the samples it saw: with few samples, optional fields can look required and coincidental values can become enums.
- The built-in validator covers the common keywords only (
if/then/else,unevaluatedProperties, remote$refand others are not checked, and it says so). Use a full validator library when strict compliance matters. - Data never leaves your machine. Enums may contain real values, so review them before publishing a schema.
How to install
- Unzip the downloaded file (it contains a
json-schema-from-samples/folder withSKILL.md). - Copy the whole folder into your agent's skills folder.
- Claude:
~/.claude/skills/(per project:.claude/skills/) - Hermes Agent:
~/.hermes/skills/ - Codex:
~/.agents/skills// Cursor:~/.cursor/skills/ - Claude app (claude.ai): upload the ZIP in Customize → Skills
- Claude:
- Restart the agent and check that the skill appears in its skill list.
Seller
AI Skill Market (official)
44 published skills