JSON Schema Validator & Generator — Infer, Validate & Document
Pricing
from $0.05 / actor start
JSON Schema Validator & Generator — Infer, Validate & Document
Infer JSON Schema from sample JSON data and validate JSON documents against existing schemas. Supports Draft-04, Draft-07, and 2019-09. Features nested objects, array item type inference, enum detection, batch validation, and human-readable schema documentation generation.
Pricing
from $0.05 / actor start
Rating
0.0
(0)
Developer
Perry AY
Maintained by CommunityActor stats
0
Bookmarked
2
Total users
1
Monthly active users
9 hours ago
Last modified
Categories
Share
JSON Schema Validator & Generator — Infer, Validate & Document Schemas
Infer JSON Schema from sample JSON data, validate JSON documents against existing schemas, and generate readable Markdown documentation from any schema. Works with JSON Schema Draft-04, Draft-07, and 2019-09.
Built with pure Python — no external schema libraries, no Playwright, no browser dependencies.
What does it do?
Three modes:
- Infer — Give it a sample JSON document, and it generates a JSON Schema that describes the structure. It works out the types (string, number, boolean, null, object, array), picks up nested properties, marks required fields, detects string formats (email, date-time, URI), and notes enum values when it sees them inside arrays.
- Validate — Give it a JSON document and a JSON Schema, and it checks every constraint in the schema against the data. Returns detailed error messages for each violation.
- Batch Validate — Run multiple validation checks in one go, each with its own data and (optionally) its own schema. Gets you per-item results plus a summary.
Features
- Schema inference — Generate a JSON Schema from any JSON sample
- Multi-draft support — Pick Draft-04, Draft-07, or 2019-09
- Type inference — Detects null, boolean, integer, number, string, array, object. Merges mixed types when it finds them (e.g. integer + float becomes "number")
- Format detection — Spots email, date-time, date, and URI string formats
- Nested object handling — Recursively walks into nested objects and arrays
- Array item type inference — Works out the type from array contents, detects enums
- Schema validation — Full constraint checking: type, enum, const, pattern, min/max, required, additionalProperties, and more
- Composition keywords — Validates allOf, anyOf, and oneOf
- $ref resolution — Resolves
$refagainst$defs - Batch validation — Process several documents and schemas in a single run
- Human-readable documentation — Auto-generates Markdown docs from any schema
- No external schema libraries — Pure Python, runs on the minimal Apify Python image
Why use this?
| Problem | Without this actor | With this actor |
|---|---|---|
| Writing JSON Schema by hand | Slow, error-prone, needs schema expertise | Generates schemas from sample JSON in milliseconds |
| Validating JSON against a schema | Need separate validation libraries and custom code | Built-in validator with full constraint checking |
| Multiple documents to validate | One-off scripts, no consistent output format | Batch mode with per-item results and summary |
| Documenting schemas | Manual docs that quickly go out of date | Auto-generates Markdown from any schema |
| Choosing a draft version | Hard-coded to one version, painful to migrate | Supports Draft-04, Draft-07, and 2019-09 |
| Complex nested data | Easy to miss required fields in deep structures | Recursive type inference with automatic required-field detection |
Who is it for?
| Persona | What they use it for |
|---|---|
| API Developer | Infers schemas automatically from sample API responses instead of writing them by hand |
| QA Engineer | Batch-validates hundreds of responses against declared schemas in test suites |
| Data Engineer | Detects structural drift in JSON pipelines and generates data contracts |
| Technical Writer | Produces Markdown schema docs for developer portals |
| Microservices Architect | Keeps service-to-service contracts consistent across Draft-07 or 2019-09 |
| Backend Developer | Validates actual API output against expected schema in CI |
| OpenAPI/Swagger Author | Generates and validates schema fragments before embedding them in specs |
| SDK/Tooling Developer | Gets machine-verified schemas for generating typed clients |
Input Parameters
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
mode | string | Yes | infer | infer, validate, or batch-validate |
data | object / array | If mode=infer or validate | {} | The JSON data to infer from or validate |
schema | object | If mode=validate | {} | The JSON Schema to validate against |
items | array | If mode=batch-validate | [] | Array of items, each with a data field (and optionally a schema field) |
default_schema | object | No | {} | Fallback schema for batch items that don't have their own |
draft | string | No | draft-07 | draft-04, draft-07, or draft-2019-09 |
Example Input — Infer Mode
{"mode": "infer","data": {"name": "Example Inc.","founded": 2020,"active": true,"website": "https://example.com","offices": [{"city": "London", "employees": 50},{"city": "Berlin", "employees": 30}]},"draft": "draft-07"}
Example Input — Validate Mode
{"mode": "validate","data": {"name": "Test", "email": "not-an-email"},"schema": {"$schema": "http://json-schema.org/draft-07/schema#","type": "object","properties": {"name": {"type": "string"},"email": {"type": "string", "format": "email"}},"required": ["name", "email"]}}
Output Format
Infer Mode Output
| Field | Type | Description |
|---|---|---|
status | string | success or error |
mode | string | infer |
schema | object | The inferred JSON Schema |
schema_json | string | Pretty-printed JSON Schema as a text string |
documentation | string | Human-readable Markdown generated from the schema |
total_properties | integer | Number of properties at the root level of the schema |
Validate Mode Output
| Field | Type | Description |
|---|---|---|
status | string | valid if the document passes, error if it doesn't |
mode | string | validate |
is_valid | boolean | true if all constraints pass |
error_count | integer | Number of validation errors found |
errors | array | Details — each entry has path (where in the document) and error (what went wrong) |
data_size_bytes | integer | Size of the input data in bytes |
Batch Validate Mode Output
Each item produces a row with:
| Field | Type | Description |
|---|---|---|
index | integer | Position in the batch (0-based) |
is_valid | boolean | Whether this item passed validation |
error_count | integer | Number of errors for this item |
errors | array | Error details |
A summary row is appended at the end with the total item count, how many passed, and how many failed.
Example Output — Infer Mode
{"status": "success","mode": "infer","schema": {"$schema": "http://json-schema.org/draft-07/schema#","type": "object","properties": {"name": {"type": "string"},"founded": {"type": "integer"},"active": {"type": "boolean"},"website": {"type": "string", "format": "uri"},"offices": {"type": "array","items": {"type": "object","properties": {"city": {"type": "string"},"employees": {"type": "integer"}},"required": ["city", "employees"],"additionalProperties": false}}},"required": ["name", "founded", "active", "offices"],"additionalProperties": false},"schema_json": "{ ... }","documentation": "# Schema Documentation\n\n...","total_properties": 5}
API Usage
cURL
curl -X POST "https://api.apify.com/v2/acts/perryay~json-schema-validator-generator/runs" \-H "Authorization: Bearer ***" \-H "Content-Type: application/json" \-d '{"mode": "infer","data": {"name": "Example Inc.","founded": 2020,"active": true},"draft": "draft-07"}'
Python (ApifyClient)
from apify_client import ApifyClientclient = ApifyClient("YOUR_API_TOKEN")result = client.actor("perryay/json-schema-validator-generator").call(run_input={"mode": "infer","data": {"name": "Example Inc.","founded": 2020,"active": True,"website": "https://example.com",},"draft": "draft-07",})dataset_items = client.dataset(result["defaultDatasetId"]).list_items()print(dataset_items[0]["schema"])
Node.js (ApifyClient)
import { ApifyClient } from 'apify-client';const client = new ApifyClient({ token: 'YOUR_API_TOKEN' });const result = await client.actor('perryay/json-schema-validator-generator').call({mode: 'infer',data: {name: 'Example Inc.',founded: 2020,active: true,website: 'https://example.com',},draft: 'draft-07',});const { items } = await client.dataset(result.defaultDatasetId).listItems();console.log(items[0].schema);
Use Cases
-
API Contract Generation — After building a new REST endpoint, collect a sample response and feed it to the Infer mode. The generated schema becomes your contract.
-
CI/CD Schema Validation — Add a step to your CI pipeline that validates every API response against its declared schema. Catch breaking changes before they ship.
-
Data Pipeline Quality Gates — In ETL pipelines that process JSON, periodically run a sample through Infer to catch structural drift — new fields, removed fields, type changes.
-
Microservice Contract Testing — When two services talk over JSON, use Validate mode in integration tests. Each service declares its expected schema.
-
Schema Migration Auditing — Upgrading from Draft-04 to Draft-07 or 2019-09? Run your existing JSON through Infer with the target draft and compare the diff.
-
OpenAPI/Swagger Schema Generation — Generate schema fragments for request/response bodies and embed them directly in your OpenAPI spec.
-
Developer Onboarding — Generate Markdown documentation from your schemas so new team members can understand the data model without reading raw schema files.
-
Batch Regression Testing — Before deploying a backend change, run Batch Validate against a corpus of historical payloads. Any failures tell you exactly what broke.
-
Third-party API Integration — If an external API doesn't provide a schema, collect sample responses and infer one yourself. Then use it to catch upstream changes.
-
Form-to-JSON Validation — For apps that accept user-submitted JSON (config files, webhook payloads), use an inferred schema as a validation layer.
FAQ
1. What JSON Schema drafts are supported?
Draft-04, Draft-07, and 2019-09. Draft-07 is the default and recommended for most use cases.
2. Can I use this without an Apify account?
The actor runs on the Apify platform. You need a free Apify account and an API token to use it programmatically.
3. How accurate is schema inference?
It's deterministic — it walks every property in your sample and assigns types based on actual values. For strings it detects formats like email, date-time, date, and URI. Enum candidates are inferred inside arrays when items have a limited set of distinct values.
4. Does the validator support $ref and $defs?
Yes. The validator resolves $ref references against $defs before applying constraints.
5. Can I validate arrays of objects?
Yes. The validator walks nested arrays and applies item schemas recursively. Batch mode accepts multiple documents.
6. What happens if my JSON is malformed?
The actor returns a clear status: "error" with a descriptive message before any schema processing starts.
7. How do I estimate usage costs?
Each run triggers a start event, then per-operation events for inference and validation. Check the Apify pricing page for current rates on platform usage.
8. Can I use this in my CI pipeline?
Yes. The actor returns machine-readable JSON that integrates with any CI system. The Python and Node.js SDKs make it easy to call from GitHub Actions, GitLab CI, or Jenkins.
9. Does inference preserve null vs missing properties?
Yes. If a property exists and its value is null, the inferred schema gives it type null. If a property is absent from the sample, it won't appear in the schema.
10. Can I customise the generated documentation?
The Markdown is auto-generated from the inferred schema. For custom formatting, you can post-process the documentation field or work with the raw schema object.
11. What happens when inference sees mixed types (e.g. a field is sometimes a string, sometimes a number)?
Mixed types only come up when items in an array have different types. The inference engine merges them into a list (e.g. ["string", "number"]). The validator checks against all listed types.
12. Does this work with large JSON documents?
Yes. The actor runs on Apify's serverless infrastructure with configurable memory. For very large documents, you can use Batch mode to split processing.
13. How does validation handle additionalProperties?
If the schema specifies additionalProperties: false, the validator reports an error for any property not listed in properties. Otherwise, extra properties are accepted.
14. Is there a free tier?
Apify offers a free usage tier with monthly credits. Check the Apify pricing page for current limits.
MCP Integration
{"mcpServers": {"apify-json-schema": {"command": "npx","args": ["-y", "@apify/mcp-server-actors", "--actors=perryay/json-schema-validator-generator"]}}}
Related Tools
- JSON Studio — Formatter, Validator & Analyzer — Format, validate, and analyse JSON documents
- Data Format Converter — Convert between JSON, YAML, TOML, CSV, and XML
SEO Keywords
JSON Schema generator, JSON Schema validator, infer JSON Schema from JSON, JSON validation tool, JSON schema draft-07, API schema generator, data contract validator, JSON schema inference engine, batch JSON validator, schema documentation generator