Use JSON Schema to document API contracts, validate JSON payloads, and generate realistic mock data for tests and demos.
Step 1 – Start from a real sample
- Paste a real API response, request payload, or config JSON into the formatter first.
- Keep one canonical JSON example per endpoint to avoid schema drift.
Step 2 – Generate a baseline schema
- Use the Schema Generator to infer types, required fields, and nested structure.
- Refine descriptions, formats, and constraints (min/max, patterns) for production use.
Step 3 – Validate JSON against the schema
- Paste your schema and real payloads into the Schema Validator.
- Fix errors by updating either the JSON sample (bugs) or the schema (contract changes).
Step 4 – Generate mock data for testing
- Open the Mock Generator to create realistic sample payloads matching your schema.
- Use seed + batch size to make test data reproducible and scalable.
Step 5 – Share and reuse
- Save schemas in version control and link them in your API docs.
- Generate typed code (TypeScript/Java/etc.) from stable JSON samples.
Important note about JSON Schema features
- Some schemas rely on advanced keywords like
$ref, anyOf, oneOf, and allOf. - Validators vary in how fully they support drafts and keywords; use a full JSON Schema validator in CI for strict compliance.
Example: JSON → JSON Schema (simplified)
// JSON input
{
"id": 1,
"name": "Maeve Winters",
"active": true,
"tags": ["developer", "backend"]
}
// Generated schema (example)
{
"type": "object",
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" },
"active": { "type": "boolean" },
"tags": {
"type": "array",
"items": { "type": "string" }
}
},
"required": ["id", "name", "active", "tags"]
}