Skip to main content
UFOZoo

JSON Schema Generator: Create Schemas from JSON Data

JSON Schema generator online: create JSON Schema from sample JSON data with type inference, nesting support, and validation-ready output.

Updated 2026-08-16

Related Tools

Features

  • Generates a JSON Schema (draft-07) from any JSON document in real time: paste JSON, get a schema instantly
  • Infers the six JSON types: string, number, integer, boolean, null, array, and object
  • Required fields toggle: mark all properties as required, or generate a fully optional schema for partial updates
  • additionalProperties toggle: choose whether validators should reject unknown keys in your objects
  • Format detection for common patterns: ISO date-time, date, email, and http(s) URIs become format keywords
  • Arrays with mixed element types get an anyOf items schema instead of being forced into one type
  • Deeply nested structures are recursed fully: nested objects, arrays of objects, and arrays of arrays
  • Integers are distinguished from decimals: 42 gets type integer, 42.5 gets type number
  • Indentation selectable between 2 and 4 spaces
  • Strict JSON validation with exact error line and column when the input is malformed
  • Drag-and-drop a .json file or use the file picker to load sample data
  • Save the schema as a .json file or copy it for use with ajv, OpenAPI specs, or TypeScript code generators

How to Use

  1. 1Paste a JSON sample into the left panel; the schema appears instantly on the right, with no convert button.
  2. 2Start with the User Profile example to see format detection: the email, date-time, and URI fields get format keywords.
  3. 3Try the Product Catalog example to see how an array of products becomes an array schema with an object items definition.
  4. 4Switch Required between All and Optional to control whether every property lands in the required list.
  5. 5Switch Additional properties between Forbid and Allow to control whether extra keys are rejected at validation time.
  6. 6Turn Format detection off if you want a schema without format keywords, for example when your strings are not really emails or dates.
  7. 7Pick 2 or 4 spaces in Indent to match the style of your project's existing schemas.
  8. 8Fix invalid input using the red error line in the left gutter; the error panel shows the message and position.
  9. 9Click the copy icon to paste the schema into ajv, a CI validation step, or an OpenAPI components/schemas block.
  10. 10Save the output as schema.json to keep it next to your API contract for future reference.

Frequently Asked Questions

What is JSON Schema?

JSON Schema is a JSON-based format for describing the structure of JSON data: which keys an object has, what types values can be, which fields are required, and what constraints apply. Validators like ajv use it to check that incoming data matches a contract, and code generators use it to produce TypeScript types or OpenAPI definitions.

Why doesn't the generated schema match what I expected?

Because the generator can only infer what your sample JSON actually shows: a key that never appears in your data cannot appear in the schema, and constraints your sample doesn't demonstrate (min/max values, enums, patterns) cannot be inferred. The generator walks your document recursively and maps each value to a type: objects become properties maps, arrays become items schemas, strings stay strings. Treat the output as a starting point, not a finished contract; add missing constraints by hand.

Which JSON Schema draft is generated?

The output targets draft-07, the most widely supported version; ajv (v6/v8), OpenAPI 3.0, and most code generators accept it. If you need newer drafts like 2020-12 (which changes how $defs and optional fields work), the generated keywords here still validate correctly with draft-07 validators.

Why is the required list empty in my generated schema?

Because the Required option is set to Optional; that produces a schema with no required list at all, useful when the same object type is used for partial updates (PATCH requests). Switch it to 'All' and every property found in the sample joins the required array. Note that inference is per sample: a key absent from your JSON won't appear in the schema at all.

Why are integer and number separate types?

In JSON Schema, integer is a stricter type than number. A sample value 42 becomes { "type": "integer" } while 42.5 becomes { "type": "number" }. This matters for validators: a schema typed integer will reject 42.5. If your API accepts decimals, change the generated type to number manually.

Why does an array with mixed types generate an anyOf items schema?

Because the generator deduplicates the element types and emits an anyOf items schema; for example [1, "a", true] becomes items: { anyOf: [{ type: "integer" }, { type: "string" }, { type: "boolean" }] }. Forcing one type would make validators reject legitimate elements. If all elements share one type, items is that single schema directly.

Why does an empty array generate a schema with no constraints?

Because an empty array [] carries no type information to infer from, so it becomes { "type": "array", "items": {} }; any element is accepted. The same happens for empty objects: {} becomes { "type": "object", "properties": {} }. Both are valid draft-07 schemas, but they impose no constraints, so refine them once you know the real data shape.

Does the generator detect formats like dates or emails?

Yes, when Format detection is on. Strings matching ISO date-time (2025-07-01T08:30:00Z), date (2025-07-01), email (name@example.com), or http(s) URI patterns get a format keyword. Note that format is only a hint; most validators need the format option enabled to enforce it, and the regexes are intentionally simple.

Why doesn't the schema include enum, min, or max constraints?

Because those constraints cannot be reliably inferred from a single sample: a value of 3 doesn't prove the minimum is 3, and the values in a sample are not the complete set of allowed values, so generating an enum would make validators reject legitimate values that simply didn't appear. The generator outputs only type-level structure; add minimum, maximum, pattern, enum, and similar keywords by hand for validation-critical fields.

Why does my JSON fail validation with an additionalProperties error?

Because the generated schema defaults to additionalProperties: false; validators reject any key that is not listed in properties. That turns the schema from a suggestion into a strict contract: typos and unexpected API fields fail loudly instead of passing silently. Switch the Additional properties option to Allow for looser validation or when objects grow dynamically.

Can I use the generated schema with ajv or OpenAPI?

Yes. The output is plain draft-07 JSON, so you can drop it into ajv (new Ajv().validate(schema, data)), an OpenAPI 3.0 components/schemas block, or a tool like json-schema-to-typescript to generate TypeScript interfaces. Remember to review the generated required and additionalProperties settings first.

Does the generator work for very large JSON files?

Yes, typical API responses and config files convert instantly. Extremely large documents (10 MB+) may slow the browser because inference recurses the whole tree locally. For schema-first projects, prefer hand-writing the schema and validating samples against it instead.

How do I generate a JSON Schema in Python, Java, or C#?

Python: pip install genson, then Genson().add_object(data).to_schema(). Java: the json-schema-generator library (everit/snowgum fork) produces draft-07 schemas from sample JSON or POJOs. C#: NJsonSchema (JsonSchema.FromJsonAsync(json) or FromType). All of these output draft-07 or compatible schemas; this tool gives the same result instantly with no setup.

Can I generate a JSON Schema with an npm package or in VS Code?

Yes. On npm, typescript-json-schema generates schemas from TypeScript interfaces (a stricter, type-driven direction), or genson-js from sample JSON. VS Code has no built-in generator; install an extension like quicktype (which also produces TypeScript and C#), or simply paste your JSON into this tool and copy the result.

What is the difference between a JSON Schema and JSON data?

JSON data is the actual information (a user record, an API response). JSON Schema is a description of that data's shape: its types, keys, and constraints. The schema is itself written in JSON, which is why it can be validated by JSON parsers and processed by the same toolchain.

Can I generate TypeScript types from the generated schema?

This tool outputs JSON Schema only. Copy the result into a code generator like json-schema-to-typescript or quicktype to produce TypeScript interfaces, or drop it into OpenAPI's components/schemas for typed clients. The draft-07 output is accepted by all of these tools.

Can this tool generate mock or fake data?

No, the direction here is data → schema. The generator infers a schema from your JSON but cannot produce sample data from a schema. For fake data generation, use a dedicated mock tool or a library like faker, or feed the generated schema into a schema-driven data generator.