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

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.

Related Tools