Skip to main content

Generate JSON Schema

Analyze a JSON document and infer types, properties, arrays and required fields automatically.

  • Clipboard
  • Export
Automate

Embed this widget

Customize the result, check the live preview, then copy the code.

Preview

Embed code type

Code to copy

Responsive and automatically resized by Bethemesh.

Was this tool useful?

How does this tool work?

Draft JSON Schema from a representative JSON document. The generator identifies types, nested objects, lists and observed properties to describe a reusable structure targeting draft 2020-12. Output is a proposal to review, not automatic discovery of every API rule. No document is uploaded to an inference service: your browser analyzes the sample and displays a JSON schema file to inspect, copy or export.

Strings become string, booleans boolean and null becomes null. Observed integers are distinguished from other numbers. Objects produce properties; arrays infer items from every supplied entry rather than only the first. Type variations can be represented using anyOf.

Properties are combined across objects in the same array. A key missing from some objects is excluded from required; a consistently present key is included. This rule only reflects samples. If the sole response includes a field that is optional in the real contract, the generator cannot infer that omission is possible.

Generated objects use additionalProperties: false, rejecting unobserved keys even when your application would accept them. Review this policy before validating future responses. An empty array provides no information about future elements, so their schema stays open instead of inventing an item type.

Inference does not invent email formats, regex constraints, numeric bounds or exhaustive allowed values. A date remains a string. Observing 1 proves neither minimum: 1 nor const: 1. Numbers use the browser’s representation; keep large identifiers as strings when that is the contract’s representation.

How to use this tool

  1. Select a useful sample

    Paste valid JSON with the complete structure. Prefer anonymized data showing relevant shapes rather than large volumes of repeated values.

  2. Generate and inspect properties

    Review inferred types, required entries and closed objects. A null value is different from an absent property.

  3. Complete and test the contract

    Add justified formats or bounds and test valid and invalid examples before integration. Downloads contain a JSON schema, not a TypeScript module.

Use cases

Draft a data contract

Start with an API response or exchange file, then compare the proposed structure with business documentation. Add constraints the sample cannot prove.

Identify array variations

Include omitted fields, present fields and nulls to distinguish required properties from allowed types. Varied samples provide a more representative starting point.

Prepare reusable validation

Use the schema with a validator supporting its draft and keywords. Generation does not install automatic checks in your application.

Examples

Infer an integer and boolean object

id becomes integer and active boolean. Both are required because they appear in the observed object; additionalProperties rejects extra keys.

Input

{"id":1,"active":true}

Result

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id": {
      "type": "integer"
    },
    "active": {
      "type": "boolean"
    }
  },
  "required": [
    "id",
    "active"
  ],
  "additionalProperties": false
}

Infer every array entry

id appears in both objects and remains required. name appears only in the second, making it a known but optional property.

Input

[{"id":1},{"id":2,"name":"Ada"}]

Result

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "id": {
        "type": "integer"
      },
      "name": {
        "type": "string"
      }
    },
    "required": [
      "id"
    ],
    "additionalProperties": false
  }
}

Tips and best practices

  • Do not turn an observed value into a business constant without other evidence. A sample does not document all allowed values.
  • Test a response with a new field to decide whether additionalProperties: false suits your service’s compatibility policy.
  • Keep omitted properties and null values in separate test cases; they express different rules.
  • Use JSON to TypeScript when you also need TypeScript interfaces or Zod schemas instead of copying structures manually.

Sources and references

Frequently asked questions

Does inference only inspect the first array entry?

No. Every supplied entry contributes. Object properties are combined and observed omissions affect required. This still analyzes samples, not unknown future data.

Why is a field required when my API makes it optional?

It was never absent from the relevant sample group. Remove it from required according to the real contract or add a representative object that omits it.

Why are extra fields rejected?

Generated objects are closed with additionalProperties: false. Change that rule when your policy permits new properties; make the choice explicitly before validating evolving data.

Does output guarantee validity of all my data?

No. It describes observed shapes and needs business review. Add relevant constraints, then run a validator supporting the draft and keywords you actually use.

Related tools

Tools similar or complementary to this one.

Similar tools

Validate a JSON document against a schema and locate every error precisely.

DevelopmentFeaturedUse this tool

Format, minify, and validate JSON to make it easier to read or more compact.

DevelopmentFeaturedUse this tool