JSON Schema Validator & Generator — Infer, Validate & Document avatar

JSON Schema Validator & Generator — Infer, Validate & Document

Pricing

from $0.05 / actor start

Go to Apify Store
JSON Schema Validator & Generator — Infer, Validate & Document

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

Perry AY

Maintained by Community

Actor stats

0

Bookmarked

2

Total users

1

Monthly active users

9 hours ago

Last modified

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:

  1. 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.
  2. 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.
  3. 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

  1. Schema inference — Generate a JSON Schema from any JSON sample
  2. Multi-draft support — Pick Draft-04, Draft-07, or 2019-09
  3. Type inference — Detects null, boolean, integer, number, string, array, object. Merges mixed types when it finds them (e.g. integer + float becomes "number")
  4. Format detection — Spots email, date-time, date, and URI string formats
  5. Nested object handling — Recursively walks into nested objects and arrays
  6. Array item type inference — Works out the type from array contents, detects enums
  7. Schema validation — Full constraint checking: type, enum, const, pattern, min/max, required, additionalProperties, and more
  8. Composition keywords — Validates allOf, anyOf, and oneOf
  9. $ref resolution — Resolves $ref against $defs
  10. Batch validation — Process several documents and schemas in a single run
  11. Human-readable documentation — Auto-generates Markdown docs from any schema
  12. No external schema libraries — Pure Python, runs on the minimal Apify Python image

Why use this?

ProblemWithout this actorWith this actor
Writing JSON Schema by handSlow, error-prone, needs schema expertiseGenerates schemas from sample JSON in milliseconds
Validating JSON against a schemaNeed separate validation libraries and custom codeBuilt-in validator with full constraint checking
Multiple documents to validateOne-off scripts, no consistent output formatBatch mode with per-item results and summary
Documenting schemasManual docs that quickly go out of dateAuto-generates Markdown from any schema
Choosing a draft versionHard-coded to one version, painful to migrateSupports Draft-04, Draft-07, and 2019-09
Complex nested dataEasy to miss required fields in deep structuresRecursive type inference with automatic required-field detection

Who is it for?

PersonaWhat they use it for
API DeveloperInfers schemas automatically from sample API responses instead of writing them by hand
QA EngineerBatch-validates hundreds of responses against declared schemas in test suites
Data EngineerDetects structural drift in JSON pipelines and generates data contracts
Technical WriterProduces Markdown schema docs for developer portals
Microservices ArchitectKeeps service-to-service contracts consistent across Draft-07 or 2019-09
Backend DeveloperValidates actual API output against expected schema in CI
OpenAPI/Swagger AuthorGenerates and validates schema fragments before embedding them in specs
SDK/Tooling DeveloperGets machine-verified schemas for generating typed clients

Input Parameters

FieldTypeRequiredDefaultDescription
modestringYesinferinfer, validate, or batch-validate
dataobject / arrayIf mode=infer or validate{}The JSON data to infer from or validate
schemaobjectIf mode=validate{}The JSON Schema to validate against
itemsarrayIf mode=batch-validate[]Array of items, each with a data field (and optionally a schema field)
default_schemaobjectNo{}Fallback schema for batch items that don't have their own
draftstringNodraft-07draft-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

FieldTypeDescription
statusstringsuccess or error
modestringinfer
schemaobjectThe inferred JSON Schema
schema_jsonstringPretty-printed JSON Schema as a text string
documentationstringHuman-readable Markdown generated from the schema
total_propertiesintegerNumber of properties at the root level of the schema

Validate Mode Output

FieldTypeDescription
statusstringvalid if the document passes, error if it doesn't
modestringvalidate
is_validbooleantrue if all constraints pass
error_countintegerNumber of validation errors found
errorsarrayDetails — each entry has path (where in the document) and error (what went wrong)
data_size_bytesintegerSize of the input data in bytes

Batch Validate Mode Output

Each item produces a row with:

FieldTypeDescription
indexintegerPosition in the batch (0-based)
is_validbooleanWhether this item passed validation
error_countintegerNumber of errors for this item
errorsarrayError 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 ApifyClient
client = 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

  1. 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.

  2. 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.

  3. 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.

  4. Microservice Contract Testing — When two services talk over JSON, use Validate mode in integration tests. Each service declares its expected schema.

  5. 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.

  6. OpenAPI/Swagger Schema Generation — Generate schema fragments for request/response bodies and embed them directly in your OpenAPI spec.

  7. Developer Onboarding — Generate Markdown documentation from your schemas so new team members can understand the data model without reading raw schema files.

  8. Batch Regression Testing — Before deploying a backend change, run Batch Validate against a corpus of historical payloads. Any failures tell you exactly what broke.

  9. 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.

  10. 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"]
}
}
}


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