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.
| Perspective | judgment |
|---|---|
| Normal cases only | Easy to mistake optional fields for required ones |
| Multiple entries including missing values | Can separate common and optional fields |
| null only | The original type other than null cannot be inferred |
| Only empty arrays | items becomes an empty Schema, so the type cannot be determined |
How to generate JSON Schema
- Paste JSON or open multiple .json files together.
- Choose Draft 2020-12 or Draft-07 for your environment.
- Configure required detection, additional properties, arrays, format, and enum inference.
- Generate the Schema and review warnings for empty arrays, null-only values, and mixed types.
- 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
| Item | Content that can be generated automatically | Items to decide manually after generation |
|---|---|---|
| Type | object, array, string, integer, number, boolean, null | Business-permitted types and type-conversion policy |
| Required fields | Three methods: all items, common items, or none | Whether it is truly required by the API contract |
| Layout | Common items or position-specific tuples | Constraints for count, duplicates, and ordering |
| Strings | Format candidates such as UUID, date and time, email, IP, and URI | Whether to validate length, pattern, and format |
| Value candidates | enum candidates when the setting is enabled | Official allowed values that include future values |
| object | Selection 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: Draft 2020-12
- JSON Schema: object
- JSON Schema: array
- JSON Schema: Combining Schemas
- Ajv: JSON Schema versions and keywords
- OpenAPI Specification 3.1.1
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.
- Prepare regular, canceled, and no-item samples without personal information.
- Open the .json files together and define required properties as those present in every sample.
- Choose the Draft and format inference settings, then generate the Schema.
- 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.