link.json
stable
  • API documentation
link.json
  • Docs »
  • link.json 0.11 documentation
  • Edit on GitHub

link.json¶

link.json provides some utilities for JSON like:

  • JSON Schema (validation and generation)
  • JSON Patch
  • Collection+JSON
  • ...

Checkout the source code on Github.

License Development Status Latest release Supported Python versions Supported Python implementations Download format Build status Code test coverage Downloads Code Health

Installation¶

pip install link.json

Contents¶

API documentation¶

link.json package¶

Submodules¶
link.json.collection module¶
class link.json.collection.CollectionJSONResponse(href, links=None, items=None, queries=None, template=None, error=None, *args, **kwargs)¶

Bases: object

Helper class used to generate valid Collection+JSON objects.

ITEM_ID = 'id'¶
json()¶

Generate JSON object.

Returns:Collection+JSON object
Return type:dict
classmethod make_item(href, document, schema=None)¶
static template_from_schema(schema)¶
link.json.collection.generate_collection_response(href, links=None, items=None, queries=None, schema=None, error=None)¶

Helper instantiating a CollectionJSONResponse class using the default schema.

Parameters:
  • href (str) – Base URL
  • links (list) – Optional list of links
  • items (list) – Optional list of items
  • queries (list) – Optional list of queries
  • schema (dict) – Optional item schema
  • error (dict) – Optional error
Returns:

Collection+JSON object

Return type:

dict

link.json.exceptions module¶
exception link.json.exceptions.JsonError¶

Bases: exceptions.Exception

Base error raised in this package.

exception link.json.exceptions.JsonTransformationError¶

Bases: link.json.exceptions.JsonError

Transformation error.

exception link.json.exceptions.JsonValidationError¶

Bases: link.json.exceptions.JsonError

Validation error.

link.json.resolver module¶
class link.json.resolver.JsonResolver(base_uri='', referrer=None, **kwargs)¶

Bases: jsonschema.validators.RefResolver

Resolve JSON references.

See: https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03

resolve_remote(uri)¶
link.json.schema module¶
class link.json.schema.JsonSchema(*args, **kwargs)¶

Bases: object

Helper class used to validate data with the JSON Schema specification.

See: http://json-schema.org

isvalid(schema_or_url, data)¶

Check if data is validated by schema.

Parameters:
  • schema_or_url (dict or str) – Schema used for validation, or URL pointing to it
  • data (any) – Data to validate
Returns:

True if data is valid, False otherwise

Return type:

bool

validate(schema_or_url, data)¶

Validate data against schema.

Parameters:
  • schema_or_url (dict or str) – Schema used for validation, or URL pointing to it
  • data (any) – Data to validate
Raises:

JsonValidationError – if data is not validated by schema

link.json.generator module¶
class link.json.generator.SchemaGenerator¶

Bases: object

Class used to generate JSON schema from data.

DRAFT = 'http://json-schema.org/draft-04/schema#'¶
exception Error¶

Bases: exceptions.Exception

Error raised when an error occured during schema generation.

SchemaGenerator.get_type(obj)¶

Get JSON type from object.

Parameters:obj (any JSON serializable basic type) – Object to guess type name from.
Returns:JSON type name
Return type:str
Raises:SchemaGenerator.Error: when obj is not a valid type
SchemaGenerator.get_unique_keys(properties, obj, required)¶

Get required keys from object.

SchemaGenerator.process_array(obj, output=None, nested=False)¶

Guess schema of array’s items.

SchemaGenerator.process_object(obj, output=None, nested=False)¶

Guess schema of object’s properties.

link.json.transform module¶
class link.json.transform.JsonTransform(source, patch, target, *args, **kwargs)¶

Bases: object

Apply a transformation on data.

A schema is used to validate the input data, and the output data. A JSON Patch is used to apply the transformation.

See: http://jsonpatch.com

patch¶
source¶
target¶
Module contents¶

Donating¶

Support via Liberapay

© Copyright 2016, David Delassus. Revision 2169a425.

Built with Sphinx using a theme provided by Read the Docs.
Read the Docs v: stable
Versions
latest
stable
Downloads
pdf
htmlzip
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.