ToolBox.Online

JSON Schema Generator — Generate JSON Schema from JSON Online [2026]

Paste JSON and get a valid JSON Schema instantly. Detects types, required fields, nested objects and arrays. Perfect for API validation, OpenAI function calling, and AI structured output. Free online tool.

What is JSON Schema Generator?

JSON Schema is a vocabulary that allows you to annotate and validate JSON documents. It defines the expected structure of JSON data — what properties exist, what types they should be, which fields are required, and how nested objects and arrays are structured. JSON Schema has become essential in the AI era. OpenAI function calling requires JSON Schema to define tool parameters. Anthropic Claude uses it for structured output. Google Gemma 4 natively supports JSON structured output with schema validation. Every major AI API now uses JSON Schema as the standard way to define expected response formats. Writing JSON Schema by hand is tedious and error-prone, especially for complex nested structures. This tool automates the process — paste an example JSON document and get a valid JSON Schema (draft-07) instantly. The generated schema includes type definitions, property descriptions, required fields, and proper handling of nested objects and arrays.

How to Use JSON Schema Generator

Paste your JSON into the left panel — the tool instantly generates a JSON Schema in the right panel. Toggle "Mark all fields required" to include or exclude the required array. Toggle "Include $schema" to add the draft-07 schema URI. Click "Copy Schema" to copy the output. Use it directly in OpenAI function calling definitions, API validators, or Gemma 4 structured output configurations.

How JSON Schema Generator Works

The generator uses recursive type inference to analyze your JSON and produce a matching schema: 1. **Type Detection:** Each value is classified as string, number, integer, boolean, null, array, or object based on JavaScript type checking. 2. **Object Processing:** For objects, the tool creates a properties map with a schema for each key, and optionally marks all keys as required. 3. **Array Processing:** For arrays, the tool examines the first element to determine the items schema. Empty arrays produce an empty items schema. 4. **Recursive Descent:** Nested objects and arrays are processed recursively, building the complete schema tree in a single pass. 5. **Schema Wrapping:** The output is wrapped with the JSON Schema draft-07 URI and root-level type definition. The tool handles edge cases including empty objects, empty arrays, null values, mixed-type arrays (falls back to empty schema), and deeply nested structures.

Common Use Cases

  • Creating OpenAI function calling schemas from example API responses
  • Defining structured output schemas for Gemma 4, Claude, and other AI models
  • Generating validation schemas for REST API request/response bodies
  • Building OpenAPI/Swagger specification components from example data
  • Creating form validation rules from existing JSON configuration files
  • Documenting API contracts by generating schemas from sample payloads

Frequently Asked Questions

Which JSON Schema draft does this tool generate?

The tool generates JSON Schema draft-07 (http://json-schema.org/draft-07/schema#), which is the most widely supported version. It works with OpenAI function calling, most validators (ajv, jsonschema), and API documentation tools like Swagger/OpenAPI 3.0.

Can I use the output for OpenAI function calling?

Yes — the generated schema is directly compatible with OpenAI function calling parameter definitions. Copy the generated schema, remove the $schema URI if needed, and paste it as the parameters field in your function definition. The same schema works for Anthropic Claude tool use and Google Gemini function declarations.

How does the tool handle nested objects and arrays?

Nested objects are processed recursively — each nested object gets its own properties map and type definitions. Arrays are handled by examining the first element to infer the items schema. Arrays of objects produce a complete nested object schema. Deeply nested structures (objects within arrays within objects) are fully supported.

How are required fields determined?

When "Mark all fields required" is enabled (the default), every property at every level is included in the required array. This is the safest default for API validation. You can toggle this off if you need optional fields, then manually edit the required arrays for your specific use case.

What happens with arrays containing different types?

If an array contains elements of different types (mixed arrays like [1, "hello", true]), the tool uses the first element to determine the items schema. For production use with mixed-type arrays, you may need to manually adjust the schema to use oneOf or anyOf. Most AI function calling schemas expect uniform arrays.

What is the difference between JSON Schema and TypeScript types?

JSON Schema validates runtime JSON data and is language-agnostic — it works in any language and is the standard for API contracts and AI function calling. TypeScript types are compile-time only and exist only in the TypeScript ecosystem. For AI applications, JSON Schema is required because it can be sent as data to the model, while TypeScript types cannot.

Related Tools

Explore More Free Tools

Discover more tools from our network — all free, browser-based, and privacy-first.