Sphinx JSON Schema

1.19.2 · active · verified Thu Apr 16

sphinx-jsonschema is a Sphinx extension that allows authors to display JSON Schema definitions directly within their documentation. It facilitates embedding schema from HTTP(S) URLs, local files, or Python objects, supporting both JSON and YAML formats. The library is actively maintained, with version 1.19.2 currently available.

Common errors

Warnings

Install

Imports

Quickstart

To quickly display a JSON Schema, install the package, add `'sphinx-jsonschema'` to the `extensions` list in your `conf.py`, and then use the `jsonschema` directive in your reStructuredText (`.rst`) files. You can refer to a local file (relative or absolute path), an HTTP(S) URL, a Python object, or embed the schema inline. Options like `:lift_title:` and `:lift_description:` control rendering behavior.

# conf.py
# ... (other Sphinx configurations)
extensions = [
    'sphinx.ext.autodoc',
    'sphinx-jsonschema'
]

# my_schema.json
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "Example Product",
  "description": "A simple product schema.",
  "type": "object",
  "properties": {
    "productId": {
      "type": "integer",
      "description": "The unique identifier for a product"
    },
    "productName": {
      "type": "string",
      "description": "Name of the product"
    }
  },
  "required": ["productId", "productName"]
}

# index.rst (or any .rst file)
.. jsonschema:: my_schema.json
   :lift_title: True
   :lift_description: True
   :encoding: utf-8

Alternatively, embed the schema directly:

.. jsonschema::
   {
     "title": "Inline Schema Example",
     "type": "string",
     "minLength": 10
   }

view raw JSON →