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]'
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fujson-0.1.2.tar.gz
(2.6 kB
view details)
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.2.tar.gz.
File metadata
- Download URL: fujson-0.1.2.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
685fbfab83ce6f6460236978837b1c264e9a374f1b686d20dd5c8fad7c2082d4
|
|
| MD5 |
e862373db6a149b097803131b64ad68f
|
|
| BLAKE2b-256 |
06242c41810eb296e323c228b955c4132eb3a8a5b458377546c09634ab59db8e
|
File details
Details for the file fujson-0.1.2-py3-none-any.whl.
File metadata
- Download URL: fujson-0.1.2-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8a0a951003bacd69ca889ba38ce0e7f0f44938c557936ff85bf1387bb042cc7
|
|
| MD5 |
822bb67102ef7a5a63bbf6061cbd164e
|
|
| BLAKE2b-256 |
b88841473944c713fab18ae1beb3ec2c5a0c482c93f164f6492bf041d836a811
|