
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
json encoder uses singledispatch pattern instead of JSONEncoder class overwrites
json encoder uses singledispatch pattern
_ instead of JSONEncoder class overwrites.
No more json.dumps(data, cls=MyJSONEncoder) everywhere.
Comes with default serialization for time, date, datetime, UUID and Decimal
Easy to use, easy to change serialization behaviour
Not tight to any json implementation json, simplejson, ujson ...
It parse json float numbers into Decimal objects to prevent python float precision issues.
.. image:: https://travis-ci.org/NZME/json-encoder.svg?branch=master&maxAge=259200 :target: https://travis-ci.org/NZME/json-encoder
.. image:: https://img.shields.io/pypi/v/json-encoder.svg?maxAge=259200 :target: https://pypi.python.org/pypi/json-encoder
.. code-block:: bash
$ pip install json-encoder
Use "json_encoder.json" instead of default python json::
from json_encoder import json
result = json.dumps(data)
Chose json implementation::
import ujson from json_encoder import use_json_library
use_json_library(ujson)
To change json implementation for concrete call do::
from json_encoder import json import simplejson
result = json.dumps(data, json=simplejson)
To make your object JSON serializable do::
from fractions import Fraction from json_encoder.encoder import json_encoder
@json_encoder.register(Fraction) def encode_fraction(obj): return '{}/{}'.format(obj.numerator, obj.denominator)
To overwrite JSON serializer behaviour defined in json_encoder.encoder::
from uuid import UUID from six import text_type from json_encoder.encoder import json_encoder
@json_encoder.register(UUID) def encode_uuid(obj): return text_type(obj).replace('-', '')
singledispatch
_ >= 3.4.0.3 for python version < 3.4 only.. _singledispatch pattern: https://docs.python.org/3/library/functools.html#functools.singledispatch .. _singledispatch: https://bitbucket.org/ambv/singledispatch
FAQs
json encoder uses singledispatch pattern instead of JSONEncoder class overwrites
We found that json-encoder demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.