This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

json-object-factory

Simplifies building custom encoders and object-hooks for Python’s default JSON implementation.

Installation

$ pip install json-object-factory

Usage

Add encoders and decoders to the registry:

import jsonfactory

class MyJsonHandler(object):
    def encode(self, o):
        if isinstance(o, MyCustomClass):
            return o.serialize()
        return None

    def decode(self, d):
        if 'some_custom_key' in d:
            return MyCustomClass(**d)
        return d

jsonfactory.Registry.register(MyJsonHandler)

Or use the included decorators:

@jsonfactory.register
class MyOtherJsonHandler(object):
    ...

@jsonfactory.encoder
def an_encoder_function(o):
    ...

@jsonfactory.decoder
def a_decoder_function(d):
    ...

Then use the module’s dumps and loads functions:

json_str = jsonfactory.dumps(obj_dict, indent=2)

new_obj_dict = jsonfactory.loads(json_str)

Notes

  • The calling signature for encoder functions follows that of the built-in JSONEncoder with one exception:
    • If no modifications are needed and the object should be passed to the base encoder’s handler, None should be returned. This differs from the normal method of calling super(MyEncoder, self).default(o) (that would most likely be an error since subclassing JSONEncoder isn’t necessary).
  • The signature for decoder functions follows the object_hook signature in the built-in implementation
Release History

Release History

0.0.2

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
json_object_factory-0.0.2-py2.py3-none-any.whl (5.5 kB) Copy SHA256 Checksum SHA256 py2.py3 Wheel Jun 1, 2016
json-object-factory-0.0.2.tar.gz (2.9 kB) Copy SHA256 Checksum SHA256 Source Jun 1, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting