/morejson

A drop-in replacement for Python's json that handles additional built-in Python types.

Primary LanguagePythonMIT LicenseMIT

morejson

PyPI-Status PyPI-Versions Build-Status Codecov LICENCE

morejson is a drop-in replacement for Python's json that handles additional built-in Python types.

import morejson as json
import datetime

json.dumps({'now': datetime.datetime.now()})
json.dumps({'set': set([1,2]), 'complex': complex(32, -4)})

Install morejson with:

pip install morejson

morejson implements the exact same API as Python's built-in json module; the dump, dumps, load and loads methods wrap around their json counterparts without changing their interface, while any other function or attribute is left unchanged.

You can use any argument of these methods, including default, cls and object_hook; morejson will wrap around any kind of custom behaviour you provide, giving it priority over morejson's encoding or decoding, and allowing you to use it with any custom JSON encoding/decoding code you have.

  • set
  • frozenset
  • complex
  • date
  • time
  • datetime
  • timedelta
  • timezone

Created by Shay Palachy (shay.palachy@gmail.com).

Inspired by a great Github gist by abhinav-upadhyay: https://gist.github.com/abhinav-upadhyay/5300137