zaggino/z-schema/writing-json-schemas
Claude Code and agent skill by zaggino/z-schema
- community
Checking that the SKILL.md file is still in the repository.
Authors JSON Schema definitions for use with z-schema validation. Use when the user needs to write a JSON Schema, define a schema for an API payload, create schemas for form validation, structure schemas with $ref and $defs, choose between oneOf/anyOf/if-then-else, design object schemas with required and additionalProperties, validate arrays with items or prefixItems, add format constraints, organize schemas for reuse, or write draft-2020-12 schemas.
Install
npx vskill@latest install zaggino/z-schema/writing-json-schemasSKILL.md
Writing JSON Schemas for z-schema
Write correct, idiomatic JSON Schemas validated by z-schema. Default target: draft-2020-12.
Schema template
Start every schema with a $schema declaration and type:
Set additionalProperties: false explicitly when extra properties should be rejected — z-schema allows them by default.
Object schemas
Basic object with required fields
Nested objects
Dynamic property names
Use patternProperties to validate property keys by regex:
Use propertyNames (draft-06+) to constrain all property key strings:
Array schemas
Uniform array
Tuple validation (draft-2020-12)
Use prefixItems for positional types, items for remaining elements:
items: false rejects extra elements beyond the tuple positions.
Contains (draft-06+)
Require at least one matching item:
With count constraints (draft-2019-09+):
String constraints
Format validation
z-schema has built-in format validators: date, date-time, time, email, idn-email, hostname, idn-hostname, ipv4, ipv6, uri, uri-reference, uri-template, iri, iri-reference, json-pointer, relative-json-pointer, regex, duration, uuid.
Format assertions are always enforced by default (formatAssertions: null). For vocabulary-aware behavior in draft-2020-12, set formatAssertions: true on the validator.
Numeric constraints
Use exclusiveMinimum / exclusiveMaximum for strict bounds:
Combinators
anyOf — match at least one
oneOf — match exactly one
allOf — match all
Use for schema composition. Combine base schemas with refinements:
not — must not match
if / then / else (draft-07+)
Conditional validation — prefer over complex oneOf when the logic is "if X then require Y":
When to use which combinator
| Scenario | Use | |
|---|---|---|
| Value can be multiple types | anyOf | |
| Exactly one variant must match | oneOf | |
| Compose inherited schemas | allOf | |
| "if condition then require fields" | if/then/else | |
| Exclude a specific shape | not |
Prefer if/then/else over oneOf when the condition is a single discriminator field — it produces clearer error messages.
Schema reuse with $ref and $defs
Local definitions
Cross-schema references
Compile an array of schemas and reference by ID:
Strict schemas with unevaluatedProperties (draft-2019-09+)
When combining schemas with allOf, additionalProperties: false in a sub-schema blocks properties defined in sibling schemas. Use unevaluatedProperties instead — it tracks all properties evaluated across applicators:
This accepts { "name": "Alice", "age": 30 } but rejects { "name": "Alice", "age": 30, "extra": true }.
Validating the schema itself
Always validate schemas at startup:
Common mistakes
- Forgetting `additionalProperties`: By default, extra properties are allowed. Set
additionalProperties: falseor useunevaluatedProperties: falseto reject them. - Using `additionalProperties: false` with `allOf`: This blocks properties from sibling schemas. Use
unevaluatedProperties: falseat the top level instead (draft-2019-09+). - Array `items` in draft-2020-12: Use
prefixItemsfor tuple validation.itemsnow means "schema for remaining items". - Missing `$schema`: Without it, z-schema uses its configured default draft. Include
$schemafor explicit draft targeting. - `definitions` vs `$defs`: Both work, but
$defsis the canonical form in draft-2019-09+. Use it consistently.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/writing-json-schemas/SKILL.md
Popularity
- Repository stars
- 350
- Repository forks
- 91
- Repository npm downloads, 7 days
- 3,195,151
- 7-day trend score
- 62
Stars and forks are for the whole GitHub repository, not this skill alone. Downloads are for the repository's npm package. Refreshed 26 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/zaggino/z-schema/writing-json-schemas)