JSON Schema for Humans

1.6.0 · active · verified Sun Apr 12

JSON Schema for Humans is a Python library that generates beautiful, human-readable static HTML documentation from JSON schemas. It helps developers understand complex schema structures at a glance. The project is actively maintained with frequent patch and minor releases, typically on a monthly or quarterly cadence, providing new features and bug fixes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically generate HTML documentation from a JSON schema file. It creates a dummy schema, saves it, and then uses `generate_from_filename` to produce an HTML output directory. You can customize the output using the `config` dictionary.

import json
import os
from json_schema_for_humans.generate import generate_from_filename

# Define a simple JSON schema
schema_data = {
    "$schema": "http://json-schema.org/draft-07/schema#",
    "title": "User Profile",
    "description": "Schema for a user profile object.",
    "type": "object",
    "properties": {
        "id": {"type": "string", "format": "uuid", "description": "Unique user ID"},
        "name": {"type": "string", "minLength": 1, "description": "Full name of the user"},
        "email": {"type": "string", "format": "email", "description": "User's email address"},
        "age": {"type": "integer", "minimum": 0, "maximum": 150, "description": "User's age"}
    },
    "required": ["id", "name", "email"]
}

# Create a directory for output and schema
os.makedirs("schema_docs_output", exist_ok=True)
schema_file_path = os.path.join("schema_docs_output", "user_profile.json")
output_dir = os.path.join("schema_docs_output", "html_docs")

# Save the schema to a file
with open(schema_file_path, "w") as f:
    json.dump(schema_data, f, indent=2)

# Generate documentation
generate_from_filename(
    schema_file_path,
    output_dir,
    config={
        "show_breadcrumbs": True,
        "link_to_top": True,
        "minify_html": True
    }
)

print(f"Documentation for '{schema_file_path}' generated successfully in '{output_dir}'.")
print("You can open index.html in that directory in your browser.")

view raw JSON →