GenSON

1.3.0 · active · verified Mon Apr 06

GenSON is a powerful, user-friendly JSON Schema generator built in Python. Its core function is to take JSON objects and generate schemas that describe them, and it is unique in its ability to merge schemas. It was originally built to describe the common structure of a large number of JSON objects. The current version is 1.3.0, released on May 15, 2024, and the library is actively maintained.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a `SchemaBuilder` and add multiple JSON objects to it. GenSON will automatically infer the common schema, merging types and determining required fields across all added objects. The resulting schema is then printed, prettified with an indent of 2.

from genson import SchemaBuilder
import json

# Initialize SchemaBuilder
builder = SchemaBuilder()

# Add the first JSON object
builder.add_object({
    "name": "Alice Johnson",
    "email": "alice@example.com",
    "age": 30,
    "is_active": True,
    "tags": ["user", "admin"]
})

# Add a second JSON object, demonstrating schema merging
builder.add_object({
    "name": "Bob Smith",
    "email": "bob@example.com",
    "age": 25,
    "phone": "+1-555-0100",
    "tags": ["user"]
})

# Generate and print the unified JSON Schema
schema = builder.to_schema()
print(json.dumps(schema, indent=2))

view raw JSON →