NR Studio
Schema Architecture Tool

JSON to JSON Schema Generator

Infer and generate Draft-07 and 2020-12 compliant JSON Schema contracts from sample JSON objects and arrays.

Sample JSON Input
Generated JSON Schema
Ready
0 properties

Why Generate JSON Schema Contracts?

Manually authoring JSON Schema files for large datasets is tedious and error-prone. This utility inspects sample payloads and derives property data types, nested structure maps, and string formats (such as RFC 3339 timestamps and email patterns) automatically.

What JSON Schema Is

JSON Schema is a declarative contract for JSON data: it states which fields must exist, what types they hold, and what values are allowed. APIs publish schemas so clients can validate payloads before processing them, catching malformed data at the boundary instead of deep in business logic. The current standard is JSON Schema 2020-12 (declared with "$schema": "https://json-schema.org/draft/2020-12/schema").

How Schema Inference Works

The generator reads your sample JSON and writes the tightest schema that accepts it: every observed key becomes a property, every value becomes a type, and every present key is listed as required. You then relax what should be optional.

Worked example
Input:
{"name": "Ada", "age": 36, "tags": ["dev"]}
Inferred schema:
{
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "age":  { "type": "integer" },
    "tags": { "type": "array", "items": { "type": "string" } }
  },
  "required": ["name", "age", "tags"]
}

JSON Schema Keywords Reference

KeywordApplies toPurpose
typeAnyAllowed type: string, integer, number, boolean, null, object, array
propertiesobjectSchemas for each named field
requiredobjectFields that must be present
additionalPropertiesobjectfalse forbids undeclared fields
itemsarraySchema every element must match
minItems / maxItemsarrayLength bounds; uniqueItems: true forbids duplicates
enumAnyFixed set of allowed values, e.g. ["red", "green"]
formatstringSemantic hint: email, date-time, uri, uuid
patternstringRegular expression the string must match
minimum / maximumnumberInclusive numeric bounds
minLength / maxLengthstringCharacter count bounds
anyOf / oneOf / allOfAnyCombine subschemas: any match / exactly one / all must match
$refAnyReuse a schema defined in $defs
descriptionAnyHuman-readable documentation (ignored by validators)

JSON Type to Schema Type Mapping

JSON valueSchema typeNotes
"text"stringAdd format or pattern for structure
36integerWhole numbers only
9.99numberAny numeric value (integer is also a valid number)
truebooleanDirect mapping
nullnullFor nullable fields use "type": ["string", "null"]
{...}objectDescribe fields under properties
[...]arrayDescribe elements under items

Tips for Production Schemas

Frequently Asked Questions About JSON Schema Generation

What is JSON Schema?

JSON Schema is a standard for describing the structure of JSON data: which fields exist, their types, and allowed values. A schema lets you validate payloads automatically, document APIs, and generate code or forms. This tool infers a schema from sample JSON so you do not have to write it by hand.

How do I generate a JSON Schema from JSON?

Paste representative JSON into the converter. It maps each value to a schema type, nests object shapes under properties, describes array elements under items, and lists observed keys as required. Review the output: relax required fields that are optional and add constraints like formats or numeric bounds.

What is the difference between integer and number in JSON Schema?

integer accepts only whole numbers (36), while number accepts any numeric value including fractions (9.99) and integers. Since every integer is a valid number, use integer when fractions are invalid (counts, ages) and number when they are allowed (prices, measurements).

What does required mean in JSON Schema?

required lists the object properties that must be present for the data to be valid. If a required key is missing, validation fails. Inferred schemas mark every observed key required; you should remove the ones that are genuinely optional in your domain.

How do I validate JSON against a schema?

Use a validator library: Ajv for JavaScript, jsonschema or python-jsonschema for Python, or an online validator. Load the schema once, then call validate(data, schema). Validators return a boolean plus a list of errors pinpointing exactly which keyword failed and where.

What is $schema and which version should I use?

$schema declares which JSON Schema dialect the document follows, for example https://json-schema.org/draft/2020-12/schema for the current 2020-12 version. Always declare it so validators interpret newer keywords correctly; 2020-12 is the recommended default for new schemas.

How do I forbid extra fields in an object?

Set additionalProperties: false on the object to reject any key not listed in properties. This catches typos like 'emial' instead of 'email'. Leave it true (the default) for extensible formats where unknown fields are acceptable.

What is the difference between anyOf, oneOf, and allOf?

anyOf passes if at least one subschema matches, oneOf passes if exactly one matches, allOf passes only if every subschema matches. Use anyOf for flexible unions, oneOf for exclusive alternatives (with careful design, since overlapping schemas cause failures), and allOf to compose constraints.

How do I validate the items inside an array?

Describe elements with items: {"type": "array", "items": {"type": "string"}}. Bound the length with minItems and maxItems, forbid duplicates with uniqueItems: true, and require at least one element with minItems: 1. For tuples (fixed positions), use prefixItems with a list of schemas.

What is $ref in JSON Schema?

$ref is a JSON pointer to another schema, letting you reuse definitions: {"$ref": "#/$defs/address"}. Put shared shapes in $defs once instead of duplicating them across properties. Refs keep large schemas maintainable and consistent.

How do I validate string formats like email or date?

Add format: email, date-time, uri, uuid, ipv4, and similar semantic hints to string schemas. Note that format is annotation-only by default in many validators (it does not fail validation unless format assertion is enabled); pair it with pattern when you need enforcement.

Can a field accept more than one type?

Pass a list of types: {"type": ["string", "null"]} accepts either a string or null. This is the standard way to model nullable fields. In older drafts the same was written with anyOf; the type array is the modern concise form.

How do I validate nested objects?

Nest schemas recursively: an object property's schema contains its own properties, required, and so on, to any depth. For deeply shared nested shapes, define them once under $defs and reference them with $ref from each location.

What is enum used for in JSON Schema?

enum restricts a value to an explicit list: {"enum": ["red", "green", "blue"]}. Anything outside the list fails validation. Use it for statuses, categories, and any closed set of allowed values; combine with type for clarity.

Is my JSON sent to a server during conversion?

No. Schema generation runs entirely in your browser; your JSON is never uploaded to any server. The generated schema is yours to copy into your project or API documentation.

Related JSON Tools

Free tool by NRTechStudio