JSON Schema Generator

Infer a JSON Schema (Draft 2020-12) from any JSON object. Detects types, nested objects, arrays, required fields, and common string formats.

What is JSON Schema?

JSON Schema is a vocabulary for describing and validating JSON data. A schema defines the shape of a JSON document — which fields exist, what types they are, which are required, and what formats strings must follow. The generated schema can be used directly with JSONKit's JSON Schema Validator.

JSON typeSchema typeNotes
string"type": "string"Optional format: email, uuid, date-time, date, uri
number (integer)"type": "integer"Only when the number has no decimal part
number (float)"type": "number"Allows any numeric value including decimals
true / false"type": "boolean"
null"type": "null"Field is optional when null in the sample
object"type": "object"Generates properties, required, additionalProperties: false
array"type": "array"items inferred from the first element

Where This Saves the Most Time

  • Bootstrapping a contract from a real payloadCapture one real API response and generate a starting schema instead of hand-writing every property from scratch.
  • Documenting an undocumented APITurn a sample response from an internal or third-party API into a schema you can attach to internal docs or an OpenAPI spec.
  • Feeding a validator or CI checkGenerate here, then paste the result straight into the JSON Schema Validator (or Ajv/jsonschema in your codebase) to start enforcing the shape.
  • Kick-starting type generationA JSON Schema is a common input for codegen tools (quicktype, json-schema-to-typescript) that produce typed interfaces across languages.
  • Spotting accidental nulls or inconsistent typesGenerating a schema from a sample forces you to notice which fields were null or unexpectedly typed in that specific response.

Using the Generated Schema in Node.js (Ajv)

javascript
// npm install ajv ajv-formats
import Ajv from "ajv";
import addFormats from "ajv-formats";

const ajv = new Ajv({ allErrors: true });
addFormats(ajv); // required for "format": "email" / "date-time" / "uuid" to be enforced

const schema = {
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "name":  { "type": "string" },
    "age":   { "type": "integer" },
    "email": { "type": "string", "format": "email" }
  },
  "required": ["name", "age", "email"],
  "additionalProperties": false
};

const validate = ajv.compile(schema);
const document = { name: "Ravi", age: 28, email: "ravi@example.com" };

if (validate(document)) {
  console.log("Document is valid");
} else {
  console.log(validate.errors);
}

Using the Generated Schema in Go

go
// go get github.com/xeipuuv/gojsonschema
import "github.com/xeipuuv/gojsonschema"

schemaLoader := gojsonschema.NewStringLoader(`{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "age":  { "type": "integer" },
    "email": { "type": "string", "format": "email" }
  },
  "required": ["name", "age", "email"],
  "additionalProperties": false
}`)

documentLoader := gojsonschema.NewStringLoader(`{"name":"Ravi","age":28,"email":"ravi@example.com"}`)

result, err := gojsonschema.Validate(schemaLoader, documentLoader)
if err != nil { panic(err) }
if result.Valid() {
  fmt.Println("Document is valid")
} else {
  for _, desc := range result.Errors() {
    fmt.Println("-", desc)
  }
}

Using the Schema in Python (Pydantic v2)

python
# pip install pydantic
from pydantic import BaseModel, EmailStr
from typing import Optional

# Or use jsonschema library directly:
# pip install jsonschema
import jsonschema, json

schema = {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
        "name":  {"type": "string"},
        "age":   {"type": "integer"},
        "email": {"type": "string", "format": "email"}
    },
    "required": ["name", "age", "email"],
    "additionalProperties": False
}

document = {"name": "Ravi", "age": 28, "email": "ravi@example.com"}
jsonschema.validate(instance=document, schema=schema)
print("Valid!")

Frequently Asked Questions

Draft 2020-12 is the latest JSON Schema version. Key differences: $defs replaces $definitions, prefixItems replaces the tuple form of items, and there are new keywords like unevaluatedProperties. Most validators support both. Draft 7 remains common in older codebases.

additionalProperties: false means the validator will reject documents that contain fields not listed in properties. This is a strict default that enforces the shape exactly. Remove it if you want to allow extra fields the schema doesn't describe.

The generator checks: ISO 8601 date-time (date + T + time), ISO date (YYYY-MM-DD), UUID (8-4-4-4-12 hex), email (@ with domain), HTTP/HTTPS URL. These are heuristics based on the sample value — always verify format constraints match your actual data.

Yes — tools like quicktype.io and json-schema-to-typescript generate TypeScript interfaces from JSON Schema. JSONKit generates the schema from your JSON; you can then feed it into those tools for type generation.

Null fields are excluded from the required array, since the sample shows they can be absent. The schema type remains the inferred type, not a nullable union. You can manually add {"anyOf": [{"type": "string"}, {"type": "null"}]} if nullability is intentional.

Yes — click Share to copy a URL with the input JSON compressed into the query string. Opening the link regenerates the same schema, with nothing stored on a server.

Yes — paste the generated schema and a sample document straight into JSONKit's JSON Schema Validator to confirm it validates as expected, including any $ref-based schemas you edit in afterward.

Related Tools