Skip to main content

alljson

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.

Installing

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

  • datetime.date 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)

Acknowledgements

Release files for alljson 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for alljson 0.2
File Size Uploaded
alljson-0.2.tar.gz 3.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for alljson 0.2
File Interpreter ABI Platform
alljson-0.2-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 8.2 kB

Release files / alljson-0.2.tar.gz

Download URL alljson-0.2.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
322b0082fab940ebabd4e12c7e306b69efb5a9bd14dafeff7f003cfe74e1ff41
BLAKE2b-256 checksum
How to use checksums
6f6966224725e118de3d69e402dc813f39e74b4aa81c227cdfad948a3f800206
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / alljson-0.2-py2.py3-none-any.whl

Download URL alljson-0.2-py2.py3-none-any.whl
Size 4.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
11ae81e7d8a61ba574b4e335553f88126df52c405244f000df8e4ebfcc148c18
BLAKE2b-256 checksum
How to use checksums
60b5b49809b7e0e357d28f47393427808ff364b42e119d0d53510943b5b19850
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2 This release

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page