complete.tools

JSON Schema Generator

Generate a JSON Schema definition from sample JSON data

What this tool does

The JSON Schema Generator analyzes sample JSON data and produces a valid JSON Schema Draft-07 definition. Paste any JSON object or array and get a ready-to-use schema with inferred types, required fields, and automatic format detection for dates, emails, and URLs.

The generated schema works with validation libraries like Ajv, Joi, and Yup, and is compatible with OpenAPI 3.0, JSON Schema validators, and TypeScript type generation tools.

What gets inferred automatically

**Types detected:** - \`string\`, \`number\`, \`integer\`, \`boolean\`, \`null\`, \`object\`, \`array\` - Nested objects and arrays are handled recursively

**String formats detected:** - \`date-time\` — ISO 8601 timestamps (e.g., "2024-01-15T10:30:00Z") - \`email\` — addresses containing @ and a domain - \`uri\` — strings starting with http:// or https://

**Other inferences:** - \`required\` array — all non-null properties are marked required - \`additionalProperties: false\` — added to all objects to prevent extra fields - Array items — uniform arrays use a single item schema; mixed arrays use \`oneOf\`

How to use

1. Paste a representative sample of your JSON into the input area 2. Enter a title for your schema (used as the \`title\` field) 3. Click Generate JSON Schema 4. Review the output and copy or download the schema 5. Add manual constraints like \`minLength\`, \`minimum\`, \`pattern\`, or \`enum\` values as needed

Using the schema for validation

**With Ajv (JavaScript):** \`\`\`javascript import Ajv from 'ajv'; const ajv = new Ajv(); const validate = ajv.compile(schema); const valid = validate(data); \`\`\`

**With Python jsonschema:** \`\`\`python import jsonschema jsonschema.validate(instance=data, schema=schema) \`\`\`

**With OpenAPI:** Paste the generated schema object into your component's \`schema\` field under \`components/schemas\`.

Limitations

The generator infers structure from a single sample, so:

- **Optional fields** — if a field is present in the sample, it's marked required. Fields that are sometimes missing won't be detected as optional. - **Enum values** — possible enum constraints won't be inferred from a single string value. - **Minimum/maximum** — numeric ranges aren't inferred; add these manually. - **Mixed types** — if a field can be \`string\` or \`null\`, you'll need to add \`"type": ["string", "null"]\` manually. - **Arrays** — mixed-type arrays use \`oneOf\`, which may be too strict for some validators.

For production schemas, always review the output and add constraints that reflect your real data requirements.

JSON Schema Draft-07 vs Draft 2019-09

This tool generates Draft-07 schemas, which is the most widely supported version across validation libraries and API tooling. Most tools that say they support "JSON Schema" mean Draft-04 or Draft-07.

Draft 2019-09 and Draft 2020-12 added features like \`\$anchor\`, \`unevaluatedProperties\`, and \`\$defs\`. If your toolchain requires a newer draft, update the \`\$schema\` URI and check your library's documentation for differences.

FAQs

Q: What is JSON Schema? A: JSON Schema is a declarative language for describing the structure and constraints of JSON data. It specifies what fields exist, their types, required vs optional status, and validation rules like minimum values or string patterns.

Q: Which draft does this generate? A: Draft-07 (https://json-schema.org/draft-07/schema#). This is the most widely supported version and works with Ajv, jsonschema (Python), OpenAPI 3.0, and most JSON Schema validators.

Q: Can I use this with TypeScript? A: Yes. Tools like json-schema-to-typescript can convert JSON Schema to TypeScript interfaces. Run the generated schema through that tool to get typed interfaces.

Q: Why are all fields marked as required? A: The generator marks all non-null fields in your sample as required. If some fields are optional in your real data, remove them from the \`required\` array in the generated schema.

Q: Does it handle nested objects? A: Yes. The generator recurses into nested objects and arrays, generating schemas for each level. The output captures your full document structure.

Q: Can I validate arrays? A: Yes. Paste a JSON array as your input. The generator infers the item schema from the array's contents and outputs an array schema with the appropriate \`items\` definition.