Skip to main content
Develop Tools
← Return to usage guide

How to Generate JSON Schema from JSON Samples

Writing JSON Schema from scratch makes it easy to miss nested objects and arrays, nullable values, and required properties. Start with safe sample data, generate the structure, and then add your business rules.

Workflow for entering JSON samples, reviewing inference warnings, and saving JSON Schema
Workflow for entering JSON samples, reviewing inference warnings, and saving JSON Schema

JSON samples to prepare before generation

  • Representative data containing normal values, empty strings, null, 0, and false
  • Samples both with and without optional properties
  • An empty array and an array containing at least one element
  • Structurally different patterns such as success and error responses

Use multiple samples with differences, not a single sample

To determine required fields as “fields present in every sample,” load multiple .json files containing not only normal cases but also cases without optional fields, nulls, empty arrays, and different array elements. Because the paste field treats its content as one JSON document, use file input for multiple samples.

Perspectivejudgment
Normal cases onlyEasy to mistake optional fields for required ones
Multiple entries including missing valuesCan separate common and optional fields
null onlyThe original type other than null cannot be inferred
Only empty arraysitems becomes an empty Schema, so the type cannot be determined

How to generate JSON Schema

  1. Paste JSON or open multiple .json files together.
  2. Choose Draft 2020-12 or Draft-07 for your environment.
  3. Configure required detection, additional properties, arrays, format, and enum inference.
  4. Generate the Schema and review warnings for empty arrays, null-only values, and mixed types.
  5. Add minimums, maximums, patterns, and descriptions to the copied or saved Schema.

What to review after generation

Values absent from the samples cannot be inferred. Compare numeric ranges, string lengths, allowed enum values, additional-property handling, and business-required fields with the API specification and consumer implementation.

format is inferred from how a string looks. An identifier may happen to resemble an email address or UUID, so verify that each inferred constraint is intentional.

Generated JSON Schema is a starting point that reduces manual work, not a finished specification. Validate it with valid and invalid data beyond the representative samples.

What can be automated with the JSON Schema generation tool

ItemContent that can be generated automaticallyItems to decide manually after generation
Typeobject, array, string, integer, number, boolean, nullBusiness-permitted types and type-conversion policy
Required fieldsThree methods: all items, common items, or noneWhether it is truly required by the API contract
LayoutCommon items or position-specific tuplesConstraints for count, duplicates, and ordering
StringsFormat candidates such as UUID, date and time, email, IP, and URIWhether to validate length, pattern, and format
Value candidatesenum candidates when the setting is enabledOfficial allowed values that include future values
objectSelection of properties and additionalProperties$defs/$ref, conditional branches, and business rules

A sample only reveals the structure of observed data. It cannot fully infer normal values, invalid values, or business contracts that do not appear in the sample.

Primary sources for checking specifications

JSON Schema dialects and the support scope of individual validators are updated over time. When incorporating it into an implementation, explicitly specify the dialect with $schema and also check the official documentation for the target library and integrated services.

Example: Build a Schema from order API responses

An order API may include a shipping address only for regular orders, a cancellation reason only for canceled orders, or an empty items array. A single successful response can make optional fields look required and leaves empty-array item types unknown.

Load regular, canceled, and no-item orders as separate JSON files. The generator can then mark only the order ID present in every sample as required while keeping other properties optional.

  1. Prepare regular, canceled, and no-item samples without personal information.
  2. Open the .json files together and define required properties as those present in every sample.
  3. Choose the Draft and format inference settings, then generate the Schema.
  4. Review warnings for empty arrays, null-only values, and mixed types, then add types and constraints from the API specification.

You do not need real customer data or credentials. Use dummy values that preserve the structure and value types.

Frequently asked questions

Can I use the generated Schema in production as-is?
Not recommended. Compare required rules, numeric ranges, string lengths, pattern, enum, and additionalProperties with the API specification, then test both valid and invalid data.
Can the generator infer the items type from an empty array?
An empty array has no element from which to infer a type. Add another sample containing an element or set items manually after generation.

Try It in Your Browser

Your input is processed entirely in your browser. Keep the original data, review the output, and only then save or share it.