Skip to main content

JSONCrack for Sphinx Extension

PyPI - Python Version PyPI - Package Version Coverage Test Summary Discord Telegram

📖 Documentation | 📊 Coverage Report | 🔬 Examples

This package provides a Sphinx extension that automatically adds JSON schemas to function and method documentation. It uses jsoncrack.com to generate beautiful, interactive HTML representations of JSON schemas.

Features

  • 🔄 Automatic schema inclusion: Schemas are automatically included in autodoc-generated documentation
  • 📁 Flexible file naming: Support for multiple naming conventions
  • 🎨 Beautiful rendering: Uses JSONCrack for rich interactive visualization
  • 🔧 Manual inclusion: schema directive for manual schema inclusion
  • 🧪 Testing support: Fixtures for testing schema documentation
  • 🌙 Dark mode: Support for dark theme styling
  • 📊 Multiple render modes: onclick, onload, and onscreen loading modes
  • 🔍 JSON && Schema: Supports both JSON schemas (.schema.json) and plain JSON files (.json)

Installation

pip install jsoncrack-for-sphinx

Quick Start

1. Configure Sphinx

Add the extension to your conf.py:

extensions = [
    "sphinx.ext.autodoc",
    "jsoncrack_for_sphinx",
]

# Configure schema directory
json_schema_dir = os.path.join(os.path.dirname(__file__), "schemas")

2. Create Schema Files

Create schema files following the naming convention:

schemas/
├── MyClass.my_method.schema.json        # Method schema
├── MyClass.my_method.options.schema.json # Method with options
├── my_function.schema.json              # Function schema
└── my_function.advanced.schema.json     # Function with options

3. Document Your Code

class MyClass:
    def my_method(self, data):
        """
        Process data according to schema.
        
        Args:
            data: Input data (schema automatically included)
        """
        pass

The schema will be automatically included in the generated documentation!

File Naming Convention

The extension searches for schema files using these patterns:

  • <ClassName>.<method>.<option-name>.schema.json
  • <ClassName>.<method>.schema.json
  • <function>.<option-name>.schema.json
  • <function>.schema.json

Note: If a function belongs to a class, the class name must be included in the filename.

Schema Search Policies

The extension provides powerful and flexible schema file search capabilities through configurable search policies:

Quick Examples

For object perekrestok_api.endpoints.catalog.ProductService.similar:

Default (include intermediate paths):

ProductService.similar.schema.json          # Highest priority
catalog.ProductService.similar.schema.json  
endpoints.catalog.ProductService.similar.schema.json
similar.schema.json

Skip intermediate paths (cleaner naming):

SearchPolicy(include_path_to_file=False)
ProductService.similar.schema.json          # Only class+method
similar.schema.json                          # Method only
# Skips: "catalog.ProductService.similar.schema.json"

Directory-based organization:

SearchPolicy(path_to_file_separator=PathSeparator.SLASH)
ProductService.similar.schema.json
endpoints/catalog/ProductService.similar.schema.json  # Uses directories
similar.schema.json

Custom API patterns:

SearchPolicy(custom_patterns=['api_{class_name}_{method_name}.json'])
api_ProductService_similar.json             # Custom pattern
ProductService.similar.schema.json          # Standard patterns

📖 Complete Search Patterns Guide - Detailed analysis of all 8 combinations with examples

Advanced Schema Search Configuration

Configurable Search Policy

The extension supports flexible schema file naming conventions through the SearchPolicy configuration. See the Complete Search Patterns Guide for detailed examples and all possible configurations.

Manual Schema Inclusion

You can also manually include schemas using the schema directive:

.. schema:: MyClass.my_method
   :title: Custom Title
   :description: Custom description
   :render_mode: onclick
   :direction: RIGHT
   :height: 500

Configuration Options

Configure the extension in your conf.py:

New Structured Configuration (Recommended)

from jsoncrack_for_sphinx.config import (
    RenderMode, Directions, Theme, ContainerConfig, RenderConfig,
    SearchPolicy, PathSeparator
)

# Required: Directory containing schema files
json_schema_dir = "path/to/schemas"

# JSONCrack configuration
jsoncrack_default_options = {
    'render': RenderConfig(
        mode=RenderMode.OnClick()  # or OnLoad(), OnScreen(threshold=0.1, margin='50px')
    ),
    'container': ContainerConfig(
        direction=Directions.RIGHT,  # TOP, RIGHT, DOWN, LEFT
        height='500',  # Height in pixels
        width='100%'   # Width in pixels or percentage
    ),
    'theme': Theme.AUTO,  # AUTO, LIGHT, DARK
    'search_policy': SearchPolicy(
        include_package_name=False,  # Include package path in search patterns
        path_to_file_separator=PathSeparator.DOT,  # How to separate path components
        path_to_class_separator=PathSeparator.DOT,  # How to separate class/method
        custom_patterns=['custom_{class_name}_{method_name}.json']  # Additional patterns
    ),
    'disable_autodoc': False,  # Disable automatic schema detection
    'autodoc_ignore': []  # List of paths to ignore in autodoc (uses "starts with" logic)
}

Legacy Configuration (Still Supported)

# Required: Directory containing schema files
json_schema_dir = "path/to/schemas"

# JSONCrack configuration
jsoncrack_render_mode = 'onclick'  # 'onclick', 'onload', or 'onscreen'
jsoncrack_theme = None  # 'light', 'dark' or None (auto-detect from page)
jsoncrack_direction = 'RIGHT'  # 'TOP', 'RIGHT', 'DOWN', 'LEFT'
jsoncrack_height = '500'  # Height in pixels
jsoncrack_width = '100%'  # Width in pixels or percentage

# Onscreen mode configuration
jsoncrack_onscreen_threshold = 0.1  # Visibility threshold (0.0-1.0)
jsoncrack_onscreen_margin = '50px'  # Root margin for early loading

# Autodoc control
jsoncrack_disable_autodoc = False  # Disable automatic schema detection
jsoncrack_autodoc_ignore = []  # List of paths to ignore in autodoc

Render Modes

  • RenderMode.OnClick(): Schema loads when user clicks the button (default)
  • RenderMode.OnLoad(): Schema loads immediately when page loads
  • RenderMode.OnScreen(threshold=0.1, margin='50px'): Schema loads automatically when visible

Render Mode Parameters

  • threshold: Percentage of element that must be visible (0.0-1.0)
  • margin: Distance before element enters viewport to start loading

Container Configuration

  • direction: Visualization direction (Directions.TOP, RIGHT, DOWN, LEFT)
  • height: Container height in pixels (string or int)
  • width: Container width in pixels or percentage (string or int)

Theme Options

  • Theme.AUTO: Auto-detect from page (default)
  • Theme.LIGHT: Force light theme
  • Theme.DARK: Force dark theme

File Types

  • .schema.json: JSON Schema files - generates fake data using JSF
  • .json: Plain JSON files - renders the JSON data as-is

Testing Support

The extension provides fixtures for testing:

from jsoncrack_for_sphinx.fixtures import schema_to_rst_fixture

def test_schema_documentation(schema_to_rst_fixture):
    rst_content = schema_to_rst_fixture(schema_path, title="Test Schema")
    assert "Test Schema" in rst_content

Development

Setup

git clone https://github.com/miskler/jsoncrack-for-sphinx.git
cd jsoncrack-for-sphinx
make install-dev

Commands

make test        # Run tests
make lint        # Run linting
make format      # Format code
make type-check  # Run type checking
make build       # Build package
make example-docs # Build example documentation

Example

See the examples/ directory for a complete working example:

cd examples/docs
sphinx-build -b html . _build/html

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Metadata

Release files for jsoncrack-for-sphinx 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jsoncrack-for-sphinx 0.1.1
File Size Uploaded
jsoncrack_for_sphinx-0.1.1.tar.gz 64.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jsoncrack-for-sphinx 0.1.1
File Interpreter ABI Platform
jsoncrack_for_sphinx-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 101.3 kB

Release files / jsoncrack_for_sphinx-0.1.1.tar.gz

Download URL jsoncrack_for_sphinx-0.1.1.tar.gz
Size 64.3 kB
Tags Source
SHA-256 checksum
How to use checksums
706bf809b9aaf81d36d5ae24cfe6b824a05bc91b03e5ddc031082a4ff59a35f4
BLAKE2b-256 checksum
How to use checksums
498e294a3da846ded0b4df5c79f392aef5e98d43aac26dbe0c9fb55f3433d01a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 22, 2025.

Transparency log

Release files / jsoncrack_for_sphinx-0.1.1-py3-none-any.whl

Download URL jsoncrack_for_sphinx-0.1.1-py3-none-any.whl
Size 37.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7ba42327aaf1c0ca0d78d9ea50486a1f3aa3afc7c9158bfc0c824952b383ce33
BLAKE2b-256 checksum
How to use checksums
a47506b55b1021cb1d396305cf9da7e99b6608d718aa10cdde17f411145292d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 22, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page