writing-json-schemas

Create draft-2020-12 JSON Schemas with $defs, $ref, and conditional constraints.

349|91|Updated Jul 23, 2013
One-click install
npx skills add https://github.com/zaggino/z-schema --skill writing-json-schemas
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: writing-json-schemas
Source: https://github.com/zaggino/z-schema/tree/main/skills/writing-json-schemas
Command: npx skills add https://github.com/zaggino/z-schema --skill writing-json-schemas

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Authors writing JSON Schemas for z-schema validation face the challenge of producing correct, reusable, and forward-compatible schemas that reflect the latest draft standards while supporting complex constructs like $ref, $defs, oneOf/anyOf/if-then-else, and array/item constraints. This Skill provides templates, patterns, and guidance to write accurate schemas that validate data consistently across APIs, forms, and payload schemas.

Core Features & Use Cases

  • Template-driven schemas with a standard header, including $schema and type declarations.
  • Structured object and nested schemas using $ref and $defs for reusable definitions.
  • Support for arrays via items and prefixItems, and advanced constraints like format, contains, and patternProperties.
  • Schema composition and conditional logic using anyOf, oneOf, allOf, not, and if/then/else for flexible validation.

Quick Start

Create a draft-2020-12 object schema with required fields name and email, and validate a sample payload against it using z-schema.

Frequently Asked Questions about writing-json-schemas

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a JSON Schema for draft-2020-12 validation?

To write a JSON Schema for draft-2020-12 validation, include a $schema declaration, specify a type, and use constructs like $defs, $ref, and format constraints to define structure. This approach ensures data validates consistently across APIs and forms.

How do I validate complex JSON payloads with oneOf and anyOf?

Validate complex JSON payloads using schema composition keywords like anyOf, oneOf, allOf, and not. These constructs allow flexible conditional logic, enabling your schema to validate diverse data structures accurately within API design scenarios.

Can I use $ref and $defs to create reusable JSON Schema definitions?

Yes, you can use $ref and $defs to create reusable JSON Schema definitions. Structuring object and nested schemas with these keywords allows you to reference internal definitions, keeping validation rules modular and maintainable.

What is the best way to validate arrays and tuple items in JSON Schemas?

The best way to validate arrays and tuple items in JSON Schemas is using items and prefixItems keywords. These array constraints, combined with advanced options like contains and patternProperties, ensure precise payload validation for ordered data.

Does z-schema support conditional if/then/else logic for API payloads?

Yes, z-schema supports conditional if/then/else logic for API payloads. This Skill provides templates and patterns to implement if/then/else alongside draft-2020-12 standards, ensuring complex form payload validation rules execute correctly.

Why does my JSON Schema validation fail for required form fields?

JSON Schema validation fails for required form fields when object schemas lack proper type declarations or required array definitions. Ensure your schema specifies required properties like name and email, and uses correct format constraints to match payload data.