# JSON Schema

> Infer a schema from JSON, validate against one, and export TypeScript and Zod.

Free JSON Schema generator and validator. Infer a schema from a sample, check a document against a schema you paste, and export TypeScript types and a Zod object. Errors include the path that failed.

- Page: https://benchline.fabwaseem.com/t/json-schema-validate
- Runs: in the browser. Input stays on the device.
- Price: free, no account
- Input: JSON text, and an optional JSON Schema.
- Output: An inferred or echoed schema, validation errors with paths, a TypeScript type, and a Zod object.
- Keywords: json schema validator, json to typescript, json to zod
- Updated: 2026-10-18
- Built by: Waseem Anjum (https://fabwaseem.com)

## How to use it

1. **Paste JSON.** A sample is enough to infer a schema, TypeScript, and Zod.
2. **Or paste a schema.** Switch to Validate and add a schema. Each error names a path such as /year.
3. **Copy the export.** The TypeScript type and the Zod object can be copied on their own.

## Use it from an AI agent

MCP tool name: `validate_json_schema`
MCP endpoint: https://benchline.fabwaseem.com/mcp (Streamable HTTP, no key)
HTTP: POST https://benchline.fabwaseem.com/api/v1/tools/json-schema-validate with the input as the JSON body
This call does not fetch anything. It runs on the arguments you send.

Infer a JSON Schema from a sample, or validate JSON against a schema. Returns error paths plus TypeScript and Zod generated from the sample.

### Input schema

```json
{
  "type": "object",
  "properties": {
    "json": {
      "type": "string",
      "description": "JSON document to infer from or validate."
    },
    "schema": {
      "description": "JSON Schema. Omit it to infer a schema from the document.",
      "type": "string"
    }
  },
  "required": [
    "json"
  ],
  "additionalProperties": false
}
```

### Example tools/call

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "validate_json_schema",
    "arguments": {
      "json": "{}"
    }
  }
}
```

Setup for Claude, Cursor, and VS Code: https://benchline.fabwaseem.com/mcp/guide

## Questions

### Does one sample describe every future document?

No. The inferred schema describes the sample. A field that is missing from the sample is not optional, and a mixed array becomes anyOf or a wider number type.

### Which schema draft is used for validation?

Validation uses Ajv. The $schema keyword is not fetched. A draft-07 document of ordinary keywords validates. The inferred schema is a plain JSON Schema object.

### Where do the TypeScript and Zod types come from?

They are generated from the inferred schema of the JSON sample. They describe the sample, not a schema you paste in the validate tab.

## Related tools

- [JSON formatter](https://benchline.fabwaseem.com/t/json-formatter): Pretty-print, minify, and validate JSON, with the exact line and column when it fails.
- [JSON YAML converter](https://benchline.fabwaseem.com/t/json-yaml-convert): Convert JSON, YAML, TOML, and XML in the browser, and keep the line number when a document fails.
- [CSV JSON converter](https://benchline.fabwaseem.com/t/csv-json-convert): Convert CSV to JSON and JSON back to CSV, with a delimiter and a header row you choose.
- [SQL formatter](https://benchline.fabwaseem.com/t/sql-formatter): Format SQL for PostgreSQL, MySQL, BigQuery, Snowflake, and other dialects.
