Skip to main content

GHGA JSON Subschema

Note: This is a fork of IBM/jsonsubschema maintained by the German Human Genome-Phenome Archive (GHGA). It was created to bring in necessary fixes, updates, and functionality required by GHGA-related projects.

ghga-jsonsubschema checks if one JSON schema is a subschema (subtype) of another.

For any two JSON schemas s1 and s2, s1 <: s2 (reads s1 is subschema/subtype of s2) if every JSON document instance that validates against s1 also validates against s2.

jsonsubschema is very useful in analysing schema evolution and ensuring that newer schema versions are backward compatible. jsonsubschema also enables static type checking on different components of a system that uses JSON schema to describe data interfaces among the system's different components.

For a practical overview of the architecture, purpose, and usage of this library, please see DETAILS.md. For the formal foundations and deep technical details, please refer to the ISSTA 2021 paper by Andrew Habib, Avraham Shinnar, Martin Hirzel, and Michael Pradel, the original authors of this library.

Installation

Requirements

  • Python 3.13+

Install from PyPI

pip install ghga-jsonsubschema

Install from source

git clone https://github.com/ghga-de/ghga-jsonsubschema.git
cd ghga-jsonsubschema
uv sync

Running subschema

JSON subschema provides two usage interfaces:

CLI interface

First, create two JSON schema examples by executing the following:

echo '{"type": ["null", "string"]}' > s1.json
echo '{"type": ["string", "null"], "not": {"enum": [""]}}' > s2.json

Then, invoke the CLI by executing:

python -m jsonsubschema s2.json s1.json

Python API

from jsonsubschema import is_subschema

def main():
    s1 = {'type': "integer"}
    s2 = {'type': ["integer", "string"]}

    print(f'LHS <: RHS {is_subschema(s1, s2)}')

if __name__ == "__main__":
    main()

Development

Set up a local development environment:

uv sync --extra dev
uv run pre-commit install

Run the test suite:

uv run pytest tests/

Run the test suite with coverage:

uv run pytest --cov tests/

Changes made by GHGA

This fork is based on version 0.0.8 of IBM/jsonsubschema and introduces additional changes:

  • Public API names have been changed to align with PEP 8.
  • The minimum required Python version is now 3.13.
  • Packaging uses more modern conventions.
  • Tests have been converted from unittest to pytest.
  • An empty enum is now treated as an uninhabited schema.
  • Bugs inherited from upstream have been fixed: negating a numeric schema now respects exclusiveMinimum/exclusiveMaximum, intersecting numeric schemas no longer drops exclusive bounds, nested anyOf unions are now fully flattened (previously, adjacent nested unions could make two equivalent schemas compare as unrelated), and arrays with at most one item are now recognized as satisfying uniqueItems.
  • The dependencies keyword (which upstream silently ignores) now raises exceptions.UnsupportedDependencies instead of potentially returning unsound verdicts.
  • Negating an integer schema (e.g. {"not": {"type": "integer", "minimum": 10, "maximum": 20}}) now yields the exact complement — including the non-integer numbers, represented internally as {"type": "number", "not": {"multipleOf": 1}} — where upstream silently computes a too-small complement that can yield unsound verdicts. Only negating a numeric schema with a non-trivial multipleOf (whose complement would contain the non-multiples) raises exceptions.UnsupportedNegatedNumeric instead of returning potentially wrong results.
  • Uninhabited numeric schemas whose multipleOf has no multiple within the schema's bounds are now recognized as such, and subtype checks of numeric schemas admitting a single value are now exact (e.g. {"type": "integer"} is now a subschema of {"type": "number", "multipleOf": 0.5}).

License

This repository is distributed under the terms of the Apache 2.0 License, see LICENSE.txt.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ghga_jsonsubschema-0.1.2.tar.gz (56.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ghga_jsonsubschema-0.1.2-py3-none-any.whl (35.8 kB view details)

Uploaded Python 3

File details

Details for the file ghga_jsonsubschema-0.1.2.tar.gz.

File metadata

  • Download URL: ghga_jsonsubschema-0.1.2.tar.gz
  • Upload date:
  • Size: 56.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for ghga_jsonsubschema-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d4e77d5db2015aea6d7b694b06f6e6e19f561eb03462c520aebab26aa97e95c8
MD5 a0d42ec599ad24098715d3a46b63a946
BLAKE2b-256 21875c0587f6614b36a517c245f6a3b9db870c932eb4691c68e5e14488f05114

See more details on using hashes here.

File details

Details for the file ghga_jsonsubschema-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for ghga_jsonsubschema-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b2c7cfb82951cd424b93405c5d1a9ea1de015d135f14a24ce0c57cbb6bc64a40
MD5 e3c426f5a5fa6c3116f4fc8b9452d466
BLAKE2b-256 3fa8d09436a41c68a3bb67f0f854718e9780adf0fe106de783b4feb0a55847ee

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.0

2 files

This release

0.1.2 This release

2 files

0.1.1

2 files

0.1.0

2 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