Skip to main content

PyPI version Build Status License

About jsonvice

jsonvice is command line tool for minifying JSON with optimal precision truncation/rounding. In many applications floating point values in JSON can be very long (15 digits or more) but this level of accuracy isn't needed and takes up much space.

jsonvice allows the truncation of all the embedded floating point numbers (wherever they appear) to a specified number of digits.

It also removes unnecessary white space to minify JSON files.

sample_input.json

{
    "x" :   12.32,
    "y": 0.23482498323433,
    "z": "simple test",
    "a" : [ 1, 2, 3.23423434343 ]
}

now run jsonvice

jsonvice -i input.json -o output.json -p 4

ouput.json

{"x":12.32,"y":0.2348,"z":"simple test","a":[1,2,3.2342]}

More Examples

compactify json and reduce floating point precision to max of 5 digits by rounding sh

jsonvice -i sample_input.json -o output.json -p 5

compactify json and reduce floating point precision to max of 5 digits by rounding down

jsonvice -i myfile.json -o output.json -p 5 -q floor

jsonvice also allows stdin / stdout pipes to be used

cat simple_test.json | python3 path/to/jsonvice.py -i - -o - > output_test.json

jsonvice can also beautify (pretty print) json, while still performing precision truncation. Note this makes the file larger.

jsonvice -i myfile.json -o output.json -p 3 -b

Building and Source

All source is at jsonvice

jsonvice is built with Python using the Poetry packaging and build tool.

pip3 install poetry # if not installed.

poetry update poetry install poetry build

poetry run jsonvice ...parameters...

Example

poetry run jsonvice -i inputfile.json -o outputfile.json -p 4

Installing as stand alone commandline tool

pip can be used into install jsonvice as stand alone tool (note python 3.6 should or later specified)

pip install jsonvice

pipx install

pipx can be used to install a stand alone version of jsonvice as a command line tool. Note pipx is like pip or pip3 but installs programs with their own virtual environment.

pipx install jsonvice

or install from github repo

pipx install git+https://github.com/deftio/jsonvice

Now you can use jsonvice at the commandline without typing python3 like this example:

jsonvice -i inputfile.json -o - -b

Python version support

Python version 3.6 or higher is required to build jsonvice. If pipx is used for install isolation takes place automatically.

Testing

Both pytest and tox were used to build jsonvice. Testing can be performed at the command line via either tool:

poetry run pytest

or

tox

History & Motivation

json vice started as a script to compactify / minify some large machine learning model files which had large floating point numbers. By rounding to fixed number of sig digits and then testing the models against testsuites to see the effects of truncation.

At the time couldn't find a tool and whipped up small script (the original script is in /dev directory).

So jsonvice was built to learn / test practices around the python poetry and pipx tools, for use in other projects, but starting with a small example cli program that already worked.

License

jsonvice uses the BSD-2 open source license

Metadata

Release files for jsonvice 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jsonvice 1.0.2
File Size Uploaded
jsonvice-1.0.2.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jsonvice 1.0.2
File Interpreter ABI Platform
jsonvice-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 11.3 kB

Release files / jsonvice-1.0.2.tar.gz

Download URL jsonvice-1.0.2.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2e11cb98eba02919109b5c1ebdc566026f40ccb84719262442d85b3ba06a46ac
BLAKE2b-256 checksum
How to use checksums
c24b62d5bc1a46a0d446211b23203d05d8ebfd0653504105b0430a64aa9abad8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.9 Darwin/23.4.0

Release files / jsonvice-1.0.2-py3-none-any.whl

Download URL jsonvice-1.0.2-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ac129a6d645fbf1ca734fd5589a13b6b9e87746a37728813fc0937f328d574da
BLAKE2b-256 checksum
How to use checksums
943278e40b111291157a9c68fa0686fea7ca0fd952bdfe860c7c2b7756f40a6e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.9 Darwin/23.4.0

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page