Skip to main content

Extendable json encode/decode library.

Project description

https://travis-ci.org/MacHu-GWU/superjson-project.svg?branch=master https://codecov.io/gh/MacHu-GWU/superjson-project/branch/master/graph/badge.svg https://img.shields.io/pypi/v/superjson.svg https://img.shields.io/pypi/l/superjson.svg https://img.shields.io/pypi/pyversions/superjson.svg https://img.shields.io/badge/Star_Me_on_GitHub!--None.svg?style=social

Welcome to superjson Documentation

Features:

  1. Support for date, datetime, set, OrderedDict, deque, numpy.ndarray, that the original json module can not serialize.
  2. Easy to extend to support any custom data type, see how.
  3. Allow // double slash started comments, # Pound key started comments style comment in json file (Good for human/machine readable config file).
  4. Use .gz for file extension, data will be automatically compressed.
  5. Atomic Write is ensured.

Usage:

>>> from collections import OrderedDict, deque
>>> from datetime import date, datetime
>>> from superjson import json
>>> import numpy as np

>>> data = {
...     "int": 1,
...     "str": "Hello",
...     "bytes": "Hello".encode("utf-8"),
...     "date": date(2010, 1, 1),
...     "datetime": datetime(2020, 1, 1, 18, 30, 0, 500),
...     "set": set([
...         datetime(2000, 1, 1),
...         datetime(2000, 1, 2),
...     ]),
...     "deque": deque([
...         deque([1, 2]),
...         deque([3, 4]),
...     ]),
...     "ordereddict": OrderedDict([
...         ("b", OrderedDict([("b", 1), ("a", 2)])),
...         ("a", OrderedDict([("b", 1), ("a", 2)])),
...     ]),
...     "array": np.array([
...         [1, 2],
...         [1.1, 2.2],
...         ["a", "b"],
...         [datetime.now(), datetime.now()],
...     ]),
... }

>>> json.dumps(data, pretty=True)
...
>>> json.dump(data, "data.gz", overwrite=True) # atomic write ensured
...

Install

superjson is released on PyPI, so all you need is:

$ pip install superjson

To upgrade to latest version:

$ pip install --upgrade superjson

Project details


Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
superjson-0.0.10-py2-none-any.whl (552.8 kB) Copy SHA256 hash SHA256 Wheel py2
superjson-0.0.10.tar.gz (439.6 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page