Skip to main content

Extended JSON encoder for Python data structures

Project description

json-ext-encoder Build Status codecov Code style: black

Extended JSON encoder for Python data structures.

A subclass of JSONEncoder, it handles these additional types:

  • datetime.datetime — a string of the form YYYY-MM-DDTHH:mm:ss.sssZ or YYYY-MM-DDTHH:mm:ss.sss+HH:MM as defined in ECMA-262.
  • datetime.date — a string of the form YYYY-MM-DD as defined in ECMA-262.
  • datetime.time — a string of the form HH:MM:ss.sss as defined in ECMA-262.
  • datetime.timedelta - a string representing a duration as defined in ISO-8601. For example, timedelta(days=1, hours=2, seconds=3.4) is represented as P1DT02H00M03.400000S.
  • decimal.Decimal, uuid.UUID — a string representation of the object.
  • enum.Enum — a .value property of enum member.

Installation

$ pip install json-ext-encoder

Usage

import json
from json_ext_encoder import JSONEncoder

json.dumps({...}, cls=JSONEncoder)

Contributing

To work on the json-ext-encoder codebase, you'll want to clone the project locally and install the required dependencies via poetry:

$ git clone git@github.com:Gr1N/json-ext-encoder.git
$ poetry install

To run tests and linters use command below:

$ poetry run tox

If you want to run only tests or linters you can explicitly specify which test environment you want to run, e.g.:

$ poetry run tox -e py37-tests

License

json-ext-encoder is licensed under the MIT license. See the license file for details.

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 json-ext-encoder, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size json_ext_encoder-0.2.0-py3-none-any.whl (6.3 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size json-ext-encoder-0.2.0.tar.gz (3.8 kB) File type Source Python version None Upload date Hashes View hashes

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