Skip to main content
Help the Python Software Foundation raise $60,000 USD by December 31st!  Building the PSF Q4 Fundraiser

Make any type JSON-serializable

Project description

Build status

Make any type JSON-serializable.

A Python module which makes json.dumps work with several builtin and stdlib types. A hook for registering any custom type is also provided.


Simply install alljson with pip or add it to your project dependencies:

pip install alljson

Supported types

After installing, the following types are JSON-serializable:

  • generators
  • set and frozenset
  • dict item/key/value iterators and views
  • and datetime.datetime (as strings in ISO format)
  • uuid.UUID
  • decimal.Decimal (serialized as string in order to preserve precision)
  • reversed results

In addition to these, the following Python 3 types are supported:

  • map, filter, range iterators
  • enum.Enum
  • pathlib.Path
  • types.MappingProxyType
  • classes implementing Sequence and Mapping abc interfaces

Registering custom types

In order to register a new type, use alljson.register_encoder(type, encoder_function). encoder_function should take object of given type as the only parameter and return a simple JSON-serializable Python value (such as dict or str).

For example:

import arrow
import alljson

alljson.register_encoder(arrow.Arrow, arrow.Arrow.isoformat)


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for alljson, version 0.2
Filename, size File type Python version Upload date Hashes
Filename, size alljson-0.2-py2.py3-none-any.whl (4.9 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size alljson-0.2.tar.gz (3.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page