A JSON Schema can be generated from JSON data by inferring types, required fields, nullability, array item shapes, and nested structure from a representative strict JSON sample.

That result is a reviewable starting point, not a complete application contract. The JSON Schema Generator converts one strict JSON value into a readable Draft 2020-12 schema and performs parsing and inference in the current tab. It does not upload the sample, run a validator, or contact a schema registry. This is structural sample inference, not schema discovery: it reports observed shapes without claiming to understand undocumented business rules.

how to generate json schema from json data
How to Generate JSON Schema from JSON Data: Review Workflow

What a generated schema establishes

The generated schema represents structural evidence found in the sample. JSON strings map to strings, safe integers map to integers, other numbers map to numbers, and Booleans and null map to their corresponding types. Objects contribute properties and required fields, arrays contribute an items schema, and nested objects and arrays are inferred recursively. If the root value is an array of objects, object presence is merged across those observed elements.

Sample evidence Generated structure Review point
JSON string type: string No format or pattern is inferred from the spelling.
Safe integer type: integer Check whether the value stayed within JavaScript's safe-integer range.
Other JSON number type: number Precision may already have been affected by JavaScript parsing.
Boolean or null type: boolean or type: null The observed value alone does not establish broader constraints.
Null plus a directly typed value The type list includes null, while properties or items remain. Nullability does not erase the non-null structure.
Incompatible observed types Deterministic anyOf branches Inspect every branch rather than assuming one preferred type.
Property present in every merged object Listed in required Requirement reflects presence, not the value's type.

For example, in {"id":7,"name":"Ava","roles":["editor"],"profile":{"active":true},"deleted_at":null}, the schema describes an integer ID, an array of strings, a nested object, and a nullable field. Because all five properties occur in this single object sample, they are required in that inferred schema. The null value means deleted_at accepts null; it does not make the property optional.

Generate and review a schema step by step

Use this workflow to turn a representative JSON value into a schema that you can inspect, copy, and test.

  1. Prepare representative strict JSON. Select one JSON value that shows the structure you need to capture. A root array of object examples can provide broader evidence about which fields are consistently present. Do not use comments, trailing commas, NaN, Infinity, undefined, BigInt, or unquoted JavaScript literals.
  2. Paste the sample and add an optional title. Open the JSON Schema Generator, paste the strict JSON, and optionally enter a concise schema title. Keep the original sample unchanged while you inspect the result.
  3. Generate the schema and inspect its important decisions. Review required fields, nullability, array items, every anyOf branch, and whether each object remains open. These are the parts most likely to need adjustment against your actual requirements.
  4. Copy the completed schema. The output declares the Draft 2020-12 dialect. Copy it into the file, configuration, or source location where your application expects to maintain its schema.
  5. Test accepted and rejected instances. Use a Draft 2020-12-capable production validator to check at least one valid instance and several deliberately invalid instances. The generator page itself does not perform this validation step.

Read inferred types without over-constraining

  • Null is a type, not an optionality marker. A property that contains null can still be required. If another merged object sample omits that property, it should not appear in the required list.
  • Mixed numeric evidence widens safely. When integer and other number values appear together, the inferred type widens to number. Incompatible observed types become deterministic anyOf branches, with duplicate equivalent branches removed.
  • Arrays reflect every observed element. The item schema is inferred from all elements observed in the array. An empty array produces an empty items schema because the sample provides no evidence for an item constraint.
  • Required fields reflect merged object presence. A property observed in every merged object sample is required. A property missing from at least one sample remains in properties but is left out of required.
  • Names and output remain stable. Property names are preserved exactly, including punctuation and prototype-shaped spellings. The same input produces deterministic output, making the generated text suitable for review and version control.

Decide whether generated objects should stay open

The generator deliberately omits additionalProperties. One sample cannot prove that keys absent from that sample are forbidden, so the generated objects remain open. This is uncertainty rather than an oversight.

Do not close an object merely because its sample contains a fixed set of keys. If an authoritative API or data contract explicitly forbids additional properties, add additionalProperties: false manually and test that policy. Otherwise, preserve the open behavior and document why it is appropriate. An extra property is not a negative validation case for an open object unless the authoritative contract says it should be rejected.

Test with the validator you actually deploy

The generated schema declares $schema: https://json-schema.org/draft/2020-12/schema, matching the JSON Schema Draft 2020-12 specification. Your validator must explicitly support that dialect. Test the copied schema with the exact validator, configuration, and vocabulary used in production rather than assuming every implementation interprets every keyword identically.

  • Start with a positive instance. Confirm that representative data accepted by your application also validates against the generated schema.
  • Add focused negative instances. Test a missing required field, an incorrect primitive type, and an invalid array item where those failures are meaningful under the inferred schema.
  • Check nullable behavior. Confirm that a null value is accepted only where the schema permits null.
  • Verify format behavior. Draft 2020-12 does not guarantee that every validator will assert format; it may remain annotation-only unless the chosen implementation enables assertion behavior.

Respect input limits and number boundaries

Generation fails cleanly when its parsing or processing limits are exceeded, so check these boundaries before submitting a large or deeply nested sample.

Constraint Supported limit Failure behavior
Input size 500,000 characters and 50,000 values No partial schema is emitted at a boundary failure.
Nesting depth 40 levels Excessive nesting causes generation to fail instead of truncating.
Output size 1,000,000 characters No partial schema is returned.
Input syntax Strict JSON only Comments, trailing commas, NaN, Infinity, undefined, BigInt, and JavaScript literals fail parsing.

JavaScript parses each sample number before inference. Only safe integers become integer, which avoids claiming exactness for larger values that may already have been rounded. Precision-sensitive decimals and identifiers may need to be represented as strings and checked with application-specific validation.

Add constraints only from authoritative requirements

The generator intentionally omits constraints that a spelling or small sample cannot establish. Add them only when a documented requirement supports them.

  • String and collection rules: format, pattern, enum, const, length limits, and uniqueness.
  • Numeric rules: minimum, maximum, and multipleOf.
  • Documentation and transfer behavior: descriptions, defaults, examples, deprecation, readOnly, writeOnly, and content encoding.
  • Composition and document identity: references, anchors, IDs, conditional logic, and unevaluated properties.

For example, a value that looks like an email address does not prove an email format, and observing one status spelling does not establish a complete enum. The generated schema remains a strong structural draft when these semantic constraints are added separately from authoritative documentation.

Before publishing, review the inferred structure, apply the required constraints, and confirm both accepted and rejected instances with the production validator. Deterministic output makes the generated schema easy to compare across revisions, but deterministic inference does not turn limited sample evidence into a complete business contract.

If you're weighing options, JSON to CSV Example: Objects, Rows, and Output covers this in detail.

If you're weighing options, JSON to Excel Bulk: One Array to One Workbook covers this in detail.