Python API, CLI, and Sphinx integration for the JSON Schema Diagram viewer
Project description
jsonschema_diagram
A frontend-first toolkit for visualizing JSON Schema as an interactive node graph, with a polished web viewer, self-contained embed artifacts, a Python API, CLI, and Sphinx integration.
Documentation | Sphinx Demo | Python API | CLI | Schema Support
✨ Features
- Interactive schema graph: render objects, arrays, refs, enums, and combinators as connected cards instead of raw JSON blocks.
- Frontend-first architecture: parsing, graph building, ref resolution, layout, search, and interaction all live in the browser.
- Embed-ready output: generate a self-contained HTML viewer for docs portals, static pages, and Sphinx.
- Python integration: use a small Python API and CLI to serve the site, render embed HTML, and integrate with docs tooling.
- Sphinx extension included: embed diagrams from inline JSON, local schema files, or a shared default schema.
- Selection and path tooling: inspect schema paths and JSON paths, copy them in multiple formats, and follow links across the graph.
- Theme-aware viewer: support clean read-only embed mode with configurable default themes.
🚀 Quick Start
Installation
For normal usage, install the published Python package:
python3 -m pip install jsonschema-diagram
You do not need npm install just to:
- serve the viewer
- render embed HTML
- use the Python API
- use the Sphinx extension
Local Viewer
Serve the viewer and the default schema endpoint:
jsonschema-diagram serve
Self-Contained Embed
jsonschema-diagram render-embed \
--schema-path schemas/default.json \
--theme slate \
--output diagram.html
30-Second Python Example
from jsonschema_diagram import load_default_schema, render_embed_html
schema = load_default_schema()
html = render_embed_html(schema, default_theme="slate")
print(html[:200])
CLI Usage
# Serve the built site plus /api/default-jsonschema
jsonschema-diagram serve --host 127.0.0.1 --port 8000
# Render a self-contained embed document
jsonschema-diagram render-embed \
--schema-path schemas/default.json \
--theme slate \
--output diagram.html
# Read schema JSON from stdin
cat schemas/default.json | jsonschema-diagram render-embed --stdin --output diagram.html
Sphinx Guide
Build the embed artifact and the docs site:
python3 -m pip install jsonschema-diagram
python3 -m pip install -r docs/requirements.txt
npm run build:embed
python3 -m sphinx -E -a -b html docs docs/_build/html
Minimal conf.py:
extensions = ["jsonschema_diagram_sphinx"]
jsonschema_diagram_embed_template = "dist/embed/jsonschema-diagram.embed.jinja2.html"
jsonschema_diagram_default_schema_path = "schemas/default.json"
jsonschema_diagram_default_height = "760px"
jsonschema_diagram_default_theme = "slate"
Minimal directive:
.. jsonschema-diagram::
:schema-file: examples/pattern-catalog.json
:theme: mono
:height: 720px
Frontend Development Only
You only need Node.js and npm install when you want to rebuild or work on the
frontend itself:
npm install
npm run dev
🧭 Viewer Modes
site
The full application experience:
- left schema input panel
- theme preset picker
- raw schema editor
- apply/reset actions
- graph canvas, search, zoom, and selection dialog
embed
The clean viewer-only mode:
- no left editor panel
- ideal for docs and static embedding
- default schema and theme are injected through runtime config or Jinja
Runtime config shape:
<script>
window.__JSONSCHEMA_DIAGRAM_CONFIG__ = {
mode: "embed",
defaultTheme: "slate",
defaultSchema: {...}
};
</script>
📦 Build Outputs
npm run build
This produces:
dist/site/index.html: normal static site builddist/embed/jsonschema-diagram.embed.html: baked standalone embed filedist/embed/jsonschema-diagram.embed.jinja2.html: Jinja2-friendly embed template
The Jinja2 embed variant accepts:
default_schemadefault_schema_jsondefault_theme
If not provided, it falls back to the shared schema in schemas/default.json and the default embed theme.
🧩 Supported Schema Features
Current core support includes:
typeformatpropertiesrequiredpatternPropertiesitemsprefixItemsenumconstanyOfoneOfallOf- local
#/...$ref
More detail is documented in Schema Support.
🐍 Python API
Public helpers currently include:
load_default_schema()load_json_schema(path)render_embed_html(schema, default_theme=...)write_embed_html(path, schema, default_theme=...)create_server(...)build_handler(...)
Example:
from jsonschema_diagram import create_server, load_json_schema, write_embed_html
schema = load_json_schema("schemas/default.json")
write_embed_html("build/diagram.html", schema, default_theme="mono")
server = create_server(host="127.0.0.1", port=8000)
server.serve_forever()
Full reference: Python API
📚 Sphinx Extension
The repository ships with jsonschema_diagram_sphinx, which embeds the viewer
through an iframe using the self-contained embed artifact.
Minimal conf.py:
extensions = ["jsonschema_diagram_sphinx"]
jsonschema_diagram_embed_template = "dist/embed/jsonschema-diagram.embed.jinja2.html"
jsonschema_diagram_default_schema_path = "schemas/default.json"
jsonschema_diagram_default_height = "760px"
jsonschema_diagram_default_theme = "slate"
Minimal directive:
.. jsonschema-diagram::
:schema-file: examples/pattern-catalog.json
:theme: mono
:height: 720px
More detail: Sphinx Extension
📖 Documentation
The repository includes a much more detailed Sphinx doc set than the demo page alone.
- Getting Started
- Viewer Modes
- Python API
- CLI
- Sphinx Extension
- Schema Support
- Troubleshooting
- Development
- Demo Page
Build the docs locally:
python3 -m pip install -r docs/requirements.txt
python3 -m sphinx -E -a -b html docs docs/_build/html
🛠️ Development
Common commands:
npm test
python3 -m unittest discover -s tests -v
npm run build
python3 -m sphinx -E -a -b html docs docs/_build/html
Python code quality commands:
make format
make lint
make type-check
These use the configured tooling:
blackisortflake8mypy
🗂️ Project Layout
src/: React + TypeScript viewerschemas/default.json: shared default schemajsonschema_diagram/: Python API and CLIjsonschema_diagram_sphinx/: Sphinx extensionbackend/: compatibility HTTP server entrypointdocs/: Sphinx documentation sourcescripts/build-embed.mjs: embed builder
📄 License
MIT License. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jsonschema_diagram-0.1.0.tar.gz.
File metadata
- Download URL: jsonschema_diagram-0.1.0.tar.gz
- Upload date:
- Size: 1.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6459a579ebd5bf9ed72579eb5d2754459e772e7d2f79bc0e39aff902859879af
|
|
| MD5 |
3a4167bc1a24f80366330968f6db83d6
|
|
| BLAKE2b-256 |
670524ac663ffe4ec90049fa06d587ebe2e7dc7cabf5dc95b4d5be9cf1be9be8
|
Provenance
The following attestation bundles were made for jsonschema_diagram-0.1.0.tar.gz:
Publisher:
release.yml on Miskler/jsonschema-diagram
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jsonschema_diagram-0.1.0.tar.gz -
Subject digest:
6459a579ebd5bf9ed72579eb5d2754459e772e7d2f79bc0e39aff902859879af - Sigstore transparency entry: 1190750250
- Sigstore integration time:
-
Permalink:
Miskler/jsonschema-diagram@a386f1da6105699a137e941b0ea6a460a65bfbed -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Miskler
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a386f1da6105699a137e941b0ea6a460a65bfbed -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file jsonschema_diagram-0.1.0-py3-none-any.whl.
File metadata
- Download URL: jsonschema_diagram-0.1.0-py3-none-any.whl
- Upload date:
- Size: 1.3 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42da976edfd8a9805cd3fe7109ea697a7813e2915e5b4275d5d2964aacb9be6e
|
|
| MD5 |
f565c474fd79f8c2df4831ba2c1033f3
|
|
| BLAKE2b-256 |
2ee6924f00cc83945f238a65ff77fee97e55bd5c41023ace453a1f4bccb9a1ce
|
Provenance
The following attestation bundles were made for jsonschema_diagram-0.1.0-py3-none-any.whl:
Publisher:
release.yml on Miskler/jsonschema-diagram
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jsonschema_diagram-0.1.0-py3-none-any.whl -
Subject digest:
42da976edfd8a9805cd3fe7109ea697a7813e2915e5b4275d5d2964aacb9be6e - Sigstore transparency entry: 1190750256
- Sigstore integration time:
-
Permalink:
Miskler/jsonschema-diagram@a386f1da6105699a137e941b0ea6a460a65bfbed -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Miskler
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a386f1da6105699a137e941b0ea6a460a65bfbed -
Trigger Event:
workflow_dispatch
-
Statement type: