PyZMQ Documentation

Table Of Contents

Previous topic

ssh.tunnel

Next topic

web.proxy

This Page

utils.jsonapi

Module: utils.jsonapi

Priority based json library imports.

Use jsonapi.loads() and jsonapi.dumps() for guaranteed symmetry.

Priority: simplejson > jsonlib2 > json

Always serializes to bytes instead of unicode for zeromq compatibility.

jsonapi.loads/dumps provide kwarg-compatibility with stdlib json.

To override pyzmq’s choice of json library, you can simply override the loads/dumps methods, e.g.:

import ujson
from zmq.utils import jsonapi
jsonapi.jsonmod = ujson
# ujson doesn't support the `separators` kwarg we use, so force its own dumps:
jsonapi.dumps = ujson.dumps

To select the super-fast ujson module. Note that using a different module such as ujson that does not support the same kwargs as stdlib json may break compatibility with other tools that depend on this, if used in the same process. A safer route is to just serialize your own messages yourself with your favorite library.

Authors

  • MinRK
  • Brian Granger

Functions

zmq.utils.jsonapi.dumps(o, **kwargs)
zmq.utils.jsonapi.loads(s, **kwargs)