# JSON Schema Inference from Sample Documents

> JSON Schema Inference from Sample Documents is a paid API for AI agents from agent402.tools, paid per call via x402, $0.001/call, status unknown (last checked 2026-09-15).

Infers a draft-07 JSON Schema from one or more sample JSON documents using heuristic merge rules

## Facts

- Endpoint: POST https://agent402.tools/api/json-schema-infer
- Price: $0.001/call
- Payment: x402
- Status: unknown
- Last checked: 2026-09-15
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/json-schema-inference-from-sample-documents-46394bef
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_y-nPkcpntVna5fol2aM92

Status and success rate cover calls made through Zero and Zero's own probes. Third-party monitors may report differently.

## How to call it through Zero

Zero handles the 402 payment challenge and records the run. With the Zero CLI installed (`npm i -g @zeroxyz/cli`):

```sh
zero fetch --capability json-schema-inference-from-sample-documents-46394bef -d '<json body>'
```

Example prompt: Can you infer a JSON Schema draft-07 from these two sample JSON objects I have? Here are the samples: {"id": 1, "name": "Alice", "score": 9.5} and {"id": 2, "name": "Bob", "active": true} — I want to know which keys are required and what types everything should be.

## When to prefer this

Use this endpoint when you have concrete JSON examples and need to quickly derive a formal JSON Schema without writing one by hand. Especially useful when merging multiple JSON samples into a single unified schema that accounts for optional fields and type variations. Prefer this over manual schema authoring when working with API responses, database exports, or user-supplied data of unknown structure.

## Known failure modes

- No json or samples field provided — returns error indicating missing input
- samples array exceeds 50 documents — returns validation error
- Malformed JSON string passed — returns parse error
- Empty samples array — returns error or empty schema
- Non-object/non-array JSON at top level may produce unexpected schema shape

## How this service works

Infer a draft-07 JSON Schema from sample JSON document(s). Send one sample as json, or several as samples. Heuristic merge rules: required = keys present in every sample, conflicting types become a type union, integer widens to number, and string formats (date-time, date, email, uri, uuid) are detected from values. Complements json-validate.

## Output

A draft-07 JSON Schema object describing the structure of the input sample(s), with required fields set to keys present in every sample, conflicting types expressed as type unions, integers widened to number when mixed with floats, and all discovered property names and their inferred types included.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "properties": {
  "json": {
   "description": "a sample JSON document (object or JSON string)"
  },
  "samples": {
   "type": "array",
   "description": "alternative: 1-50 sample documents merged into one schema"
  }
 }
}
```

## Response schema (JSON Schema)

```json
{
 "type": "json",
 "example": {
  "schema": {
   "type": "object",
   "$schema": "http://json-schema.org/draft-07/schema#",
   "required": [
    "name",
    "age"
   ],
   "properties": {
    "age": {
     "type": "integer"
    },
    "name": {
     "type": "string"
    }
   }
  },
  "samples": 1
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/json-schema-inference-from-sample-documents-46394bef/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from agent402.tools](https://www.zero.xyz/host/agent402.tools/llms.txt)
