# JSON Schema Contract Validator (`colt2822/json-schema-contract-validator`) Actor

Validate JSON/JSONL records against your JSON Schema, or infer a schema + TypeScript interface from a sample. Per-record errors and VALID/DEAD_LETTER files.

- **URL**: https://apify.com/colt2822/json-schema-contract-validator.md
- **Developed by:** [Colton Mcclain](https://apify.com/colt2822) (community)
- **Categories:** Developer tools
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.30 / 1,000 record validateds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## JSON Schema Contract Validator

**Enforce a data contract on scraped or exported data and see exactly which records break it.**

### What problem does it solve?

Pipelines break when a source quietly changes shape. You need a clear valid / dead-letter split and the reason for every rejected record.

### What it does

- Validates each record against your JSON Schema with the Python jsonschema library.
- Reports up to 10 violations per record (JSON-pointer path, message, keyword) and exact error counts.
- Writes VALID.jsonl and DEAD_LETTER.jsonl to the key-value store.
- Or infers a schema and TypeScript interface from a sample (required = present in every row).

### Pricing (pay per event)

| Event | Price |
|---|---|
| Actor start (once per run, per GB of memory, minimum one) | $0.0050 |
| Record validated (per record validated) | $0.0003 |

You pay only for the events above plus nothing else from ELYRAON; Apify platform usage is covered by the event prices. The start event is charged on every run, including a run rejected for invalid input (nothing else is charged in that case). If you set a maximum charge per run, the Actor stops when it is reached and reports `PARTIAL_MAX_CHARGE` in the OUTPUT record, so you are never silently billed beyond your cap and never told a partial result is complete.

### Input

| Field | Title | Required | Description |
|---|---|---|---|
| `records` | Records | no | Records to process. Each item is a JSON object or a plain string. |
| `file_url` | File URL | no | Public http(s) URL of a JSON array or JSONL file. Use instead of Records. |
| `schema` | JSON Schema | no | Your JSON Schema (draft 4-2020-12; local $refs only). Use this OR Infer schema. |
| `infer_schema` | Infer schema from the records | no | Build a schema (and TypeScript interface) from your sample instead of validating against one. |

Example input:

```json
{
  "records": [
    {
      "id": 1
    }
  ],
  "schema": {
    "type": "object",
    "required": [
      "id",
      "name"
    ]
  }
}
```

### Output

Results go to the run's default dataset (download as JSON, CSV or Excel). Each item:

| Field | Type | Description |
|---|---|---|
| `record_index` | integer | 1-based position. |
| `valid` | boolean | Passed the schema. |
| `error_count` | integer | Total violations. |
| `errors` | array | Up to 10 violations: path, message, keyword. |

Example item:

```json
{
  "record_index": 1,
  "valid": false,
  "error_count": 1,
  "errors": [
    {
      "path": "/",
      "message": "'name' is a required property",
      "keyword": "required"
    }
  ]
}
```

The key-value store holds `OUTPUT` (run summary: status, counts, warnings, limitations, version, source commit) and `REPORT.md` (readable summary). `OUTPUT.status` is `SUCCEEDED`, `PARTIAL_MAX_CHARGE`, `PARTIAL_RESULT_LIMIT` or `FAILED` (with a structured `error` code/message/field). Invalid or empty input fails the run immediately with an explanation and returns no results.

### Use from code

```bash
curl -X POST "https://api.apify.com/v2/acts/colt2822~json-schema-contract-validator/run-sync-get-dataset-items?token=$APIFY_TOKEN" \
  -H "Content-Type: application/json" -d '{"records": [{"id": 1}], "schema": {"type": "object", "required": ["id", "name"]}}'
```

```python
from apify_client import ApifyClient
run = ApifyClient("$APIFY_TOKEN").actor("colt2822/json-schema-contract-validator").call(run_input={"records": [{"id": 1}], "schema": {"type": "object", "required": ["id", "name"]}})
```

This Actor can also be called by AI agents through the Apify MCP server (https://mcp.apify.com), which exposes Actors as tools.

### Limitations

- Remote $ref fetching is not supported.
- An inferred schema describes your sample, not your intended contract: review before enforcing.
- Max 50,000 records per run.

### Support

Questions or problems: https://elyraon.com.co/contact/ (ELYRAON). Source revision: `64dbaa5`. Actor version 1.0.

# Actor input Schema

## `records` (type: `array`):

Records to process. Each item is a JSON object or a plain string.

## `file_url` (type: `string`):

Public http(s) URL of a JSON array or JSONL file. Use instead of Records.

## `schema` (type: `object`):

Your JSON Schema (draft 4-2020-12; local $refs only). Use this OR Infer schema.

## `infer_schema` (type: `boolean`):

Build a schema (and TypeScript interface) from your sample instead of validating against one.

## Actor input object example

```json
{
  "records": [
    {
      "id": 1,
      "email": "a@b.co",
      "age": 31
    },
    {
      "id": "two",
      "email": "x",
      "age": -4
    },
    {
      "id": 3,
      "email": "c@d.io"
    }
  ],
  "schema": {
    "type": "object",
    "required": [
      "id",
      "email",
      "age"
    ],
    "properties": {
      "id": {
        "type": "integer"
      },
      "email": {
        "type": "string",
        "pattern": "^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$"
      },
      "age": {
        "type": "integer",
        "minimum": 0
      }
    }
  },
  "infer_schema": false
}
```

# Actor output Schema

## `results` (type: `string`):

No description

## `summary` (type: `string`):

No description

## `report` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "records": [
        {
            "id": 1,
            "email": "a@b.co",
            "age": 31
        },
        {
            "id": "two",
            "email": "x",
            "age": -4
        },
        {
            "id": 3,
            "email": "c@d.io"
        }
    ],
    "schema": {
        "type": "object",
        "required": [
            "id",
            "email",
            "age"
        ],
        "properties": {
            "id": {
                "type": "integer"
            },
            "email": {
                "type": "string",
                "pattern": "^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$"
            },
            "age": {
                "type": "integer",
                "minimum": 0
            }
        }
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("colt2822/json-schema-contract-validator").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "records": [
        {
            "id": 1,
            "email": "a@b.co",
            "age": 31,
        },
        {
            "id": "two",
            "email": "x",
            "age": -4,
        },
        {
            "id": 3,
            "email": "c@d.io",
        },
    ],
    "schema": {
        "type": "object",
        "required": [
            "id",
            "email",
            "age",
        ],
        "properties": {
            "id": { "type": "integer" },
            "email": {
                "type": "string",
                "pattern": "^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$",
            },
            "age": {
                "type": "integer",
                "minimum": 0,
            },
        },
    },
}

# Run the Actor and wait for it to finish
run = client.actor("colt2822/json-schema-contract-validator").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "records": [
    {
      "id": 1,
      "email": "a@b.co",
      "age": 31
    },
    {
      "id": "two",
      "email": "x",
      "age": -4
    },
    {
      "id": 3,
      "email": "c@d.io"
    }
  ],
  "schema": {
    "type": "object",
    "required": [
      "id",
      "email",
      "age"
    ],
    "properties": {
      "id": {
        "type": "integer"
      },
      "email": {
        "type": "string",
        "pattern": "^[^@\\\\s]+@[^@\\\\s]+\\\\.[^@\\\\s]+$"
      },
      "age": {
        "type": "integer",
        "minimum": 0
      }
    }
  }
}' |
apify call colt2822/json-schema-contract-validator --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,colt2822/json-schema-contract-validator"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/W7z7vPROscd2eXJeg/builds/CRDUbgIFsXe8fdrnZ/openapi.json
