API Docs

JSONResolver

Resolve JSON objects from different URLs.

class jsonresolver.core.JSONResolver(plugins=None, entry_point_group=None)[source]

Resolve JSON objects based on rules in URL map.

resolve(url)[source]

Resolve given URL and use regitered loader.

Contrib

This package contains utilities for various JSON packages.

Usually one has to install extra dependencies.

If you would like to use reference resolver factory for jsonschema please install jsonresolver with jsonschema extras.

$ pip install jsonresolver[jsonschema]

JSONSchema

Module that implements RefResolver factory using JSONResolver.

The ref_resolver_factory uses an instance of JSONResolver for implementation of remote URL resolver. The resolver is used to retrieve JSON object based on registered plugins.

Example:

>>> from jsonschema import validate
>>> from jsonresolver import JSONResolver
>>> from jsonresolver.contrib.jsonschema import ref_resolver_factory
>>> schema = {'$ref': 'http://localhost:4000/schema/authors.json#'}
>>> json_resolver = JSONResolver(plugins=['demo.schema'])
>>> resolver_cls = ref_resolver_factory(json_resolver)
>>> resolver = resolver_cls.from_schema(schema)
>>> validate(['foo', 'bar'], schema, resolver=resolver)
None
jsonresolver.contrib.jsonschema.ref_resolver_factory(resolver)[source]

Generate new RefResolver class that uses given resolver.

JSONRef

Module that implements JsonLoader factory using JSONResolver.

Use json_loader_factory if you want to take advantage of default JsonLoader.get_remote_json method for URIs that are not handled by your JSONResolver instance.

Example:

>>> from jsonref import JsonRef
>>> from jsonresolver import JSONResolver
>>> from jsonresolver.contrib.jsonref import json_loader_factory
>>> schema = {'$ref': 'http://localhost:4000/schema/authors.json#'}
>>> json_resolver = JSONResolver(plugins=['demo.schema'])
>>> loader_cls = json_loader_factory(json_resolver)
>>> loader = loader_cls(cache_results=False)
>>> dict(JsonRef.replace_refs(schema, loader=loader))
{'type': 'array'}
# if you do not want default fallback:
>>> dict(JsonRef.replace_refs(schema, loader=json_resolver.resolve))
{'type': 'array'}
jsonresolver.contrib.jsonref.json_loader_factory(resolver)[source]

Generate new JsonLoader class that uses given resolver.