Usage

To use JSON API doc in a project:

import json_api_doc

The module provides 2 functions, serialize and deserialize.

To transform the JSON API document into a simple denormalized Python dict use deserialize:

document =  {
    'data': {
        'type': 'article,
        'id': '1',
        'attributes': {
            'name': 'Article 1'
        }
    }
}
json_api_doc.deserialize(document)

To transform the a Python dict object into a normalized JSON API document use serialize:

obj =  {
    '$type': 'article,
    'id': '1',
    'name': 'Article 1'
}
json_api_doc.serialize(document)
json_api_doc.serialize(data={}, errors={}, meta={}, links={})[source]
Parameters:
  • data – Dict with data to serialize
  • errors – Dict with error data to serialize
  • meta – Dict with meta data to serialize
Returns:

Dict normalized as a valid JSON API document

json_api_doc.deserialize(content)[source]
Parameters:content – A JSON API document already
Returns:The JSON API document parsed