Float formatting control for JSON encoding.
Project description
FuJSON: less decimals, more fuzzy JSON
FuJSON is a Python module that allows to control the formatting of floats when JSON encoding, typically to dial down the number of decimals.
It builds on the standard library's json.JSONEncoder
and monkey-patches it to inject custom float formatting.
Usage
Simple dumps call:
>>> from fujson import dumps
>>> dumps({"x": 1.23456789}, float_format=".2f")
'{"x": 1.23}'
Reusable encoder:
>>> from fujson import FuJsonEncoder
>>> encoder = FuJsonEncoder(float_format=".2f")
>>> encoder.encode({"x": 1.23456789})
'{"x": 1.23}'
>>> encoder.encode([1.1, 2.22, 3.333, 4.4444])
'[1.10, 2.22, 3.33, 4.44]'
Do JSON dump with floats in scientific notation:
>>> from fujson import FuJsonEncoder
>>> encoder = FuJsonEncoder(float_format=".2e")
>>> encoder.encode([.123, 0.0000123, 12345678.9])
'[1.23e-01, 1.23e-05, 1.23e+07]'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fujson-0.1.0.tar.gz.
File metadata
- Download URL: fujson-0.1.0.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.7.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ed2fe33d254ba3a772c3d080e093ca497b33fe79e674821d95c87fda07be1e2
|
|
| MD5 |
9405c7d26fdd44cc54c97ee061d813cb
|
|
| BLAKE2b-256 |
e02f76aef4c996694250a62742d13ce5d29bb789463b19d21b6961a2f87a710d
|
File details
Details for the file fujson-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fujson-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.7.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aece7df89d9a265cf493c63d30c88f6d56d5da096e0343ae6a96b131376617d9
|
|
| MD5 |
b69a34f005bc766bc50f2124b79fa471
|
|
| BLAKE2b-256 |
e9a626e71afc4bdc506ba0ced742fe984b86ecc1498d38b6059ad192c640db49
|