{ JSON Schema Generator }

// infer draft-07 schema from any json sample

Instantly generate a JSON Schema draft-07 from any sample JSON object. Infer types, required fields, nested objects, and array schemas online free.

{ }

Schema will appear here

Paste JSON and click Generate Schema

HOW TO USE

  1. 01
    Paste JSON

    Paste any valid JSON object or array into the input panel. Use the Sample button to try an example.

  2. 02
    Configure options

    Choose schema draft version, how required fields are marked, and whether to allow additional properties.

  3. 03
    Generate & copy

    Click Generate Schema. Copy the output or download it as a .json file for immediate use.

FEATURES

Draft-07 Recursive Format detection Array schemas Nullable types Download JSON

USE CASES

  • ๐Ÿ”ง Validate API responses with AJV or similar
  • ๐Ÿ”ง Document REST API payload contracts
  • ๐Ÿ”ง Bootstrap TypeScript types via json-schema-to-ts
  • ๐Ÿ”ง Generate form validation rules automatically
  • ๐Ÿ”ง Create OpenAPI component schemas quickly

WHAT IS THIS?

A JSON Schema Generator infers a valid draft-07 (or later) schema document from a sample JSON value. It examines each key's type, detects common formats like email and date-time, handles deeply nested objects and arrays, and marks fields as required โ€” producing a schema you can plug straight into validators like AJV, FastAPI, or Pydantic.

RELATED TOOLS

FREQUENTLY ASKED QUESTIONS

What is JSON Schema draft-07?

Draft-07 is a widely supported version of the JSON Schema specification that adds features like if/then/else, readOnly, and writeOnly. It is the default schema dialect used by many validators including AJV, and is supported natively in VS Code for IDE completion.

Can I use the generated schema with AJV?

Yes. The output is a valid draft-07 schema you can pass directly to AJV. Install AJV via npm, call ajv.compile(schema), then validate(data). The additionalProperties: false option (default) will reject any key not listed in the schema.

How are array item types inferred?

The generator inspects the first element of each array to determine the items schema. If the array contains objects, it recurses into that object to build a full nested schema. Empty arrays result in an items: {} (any type allowed).

What formats does the tool detect?

When "Infer formats" is enabled, the tool tests string values against common patterns and attaches a format keyword for: email, uri, date, time, date-time, ipv4, ipv6, and uuid.

Does it support nullable fields?

Yes. When a value is null, the generator produces "type": ["string", "null"] (or the inferred type plus null) to represent nullable fields correctly under draft-07 semantics. In 2019-09 and later, it uses oneOf with a null branch.

Will the schema work for OpenAPI 3.0?

OpenAPI 3.0 uses a subset of JSON Schema draft-04 with some draft-07 additions. Most generated schemas are compatible, but OpenAPI does not support $schema, if/then, or certain keywords. Use the Download button and adjust nullable: true if needed.

Is my JSON data sent to a server?

No. All schema inference runs entirely in your browser using JavaScript. Your JSON never leaves your machine โ€” there is no server-side processing, no logging, and no data retention.

How do I handle arrays of mixed types?

The generator inspects the first array element. If your array genuinely contains mixed types, you can manually edit the downloaded schema to use "items": {"oneOf": [...]}. The visual tree view shows what was inferred so you can spot mixed arrays easily.

What is a JSON Schema Generator?

A JSON Schema Generator is a tool that automatically derives a formal schema document from a concrete JSON sample. Instead of hand-writing every type annotation, required array, and nested object definition, you provide one example payload and the generator infers the structure for you. The result is a valid JSON Schema document โ€” most commonly targeting draft-07 โ€” that you can immediately use with validators, code generators, documentation tools, and API frameworks.

๐Ÿ’ก Looking for premium web development assets? MonsterONE offers unlimited downloads of templates, UI kits, and developer assets โ€” worth checking out.

Why Use JSON Schema?

JSON Schema provides a vocabulary to describe the structure, content, and semantics of JSON data. Adopting it brings several practical benefits to API development:

Understanding Draft-07 vs. Newer Drafts

JSON Schema has evolved through several draft versions. Draft-07 (published 2018) remains the most widely implemented version across the ecosystem. It introduced the if, then, else keywords for conditional schemas, readOnly and writeOnly annotations, and the $comment keyword for human-readable notes.

Draft 2019-09 brought recursive references ($recursiveRef), vocabularies, and unevaluatedProperties. Draft 2020-12 cleaned up the spec further and added prefixItems for tuple validation. For most use cases, draft-07 is the safest choice due to near-universal validator support.

How Schema Inference Works

The inference engine in this tool uses the following logic for each JSON value:

For nested objects, the engine recurses. The depth counter in the stats bar shows how deeply nested your sample is, which is useful for spotting unexpectedly complex payloads.

From Schema to Code: A Practical Workflow

A common workflow for API developers:

  1. Copy a real API response from your browser DevTools or Postman.
  2. Paste it into this generator and click Generate Schema.
  3. Adjust the required array to reflect which fields are truly mandatory vs. optional.
  4. Download the .json file and commit it to your repository under schemas/.
  5. Reference the schema in your validation middleware: ajv.compile(require('./schemas/response.json')).
  6. Run json-schema-to-ts or quicktype in CI to regenerate TypeScript types from the schema automatically.

Tips for Better Schema Quality

Inferred schemas are a starting point. To make them production-ready, consider adding:

Always validate the schema itself against the JSON Schema meta-schema before deploying to production. The JSON Schema Validator tool on this site can help with that step.

Integrating with OpenAPI

OpenAPI 3.0 and 3.1 embed JSON Schema for component definitions. After generating a schema here, copy the properties object into your OpenAPI YAML or JSON under components.schemas.YourModel. Note that OpenAPI 3.0 uses a dialect of draft-04 โ€” replace $schema with nothing (OpenAPI infers it) and use nullable: true instead of type: [T, null]. OpenAPI 3.1 fully supports draft 2020-12 and is more permissive.

โ˜•