Minify JSON to reduce LLM API token costs
Project description
minson
minify + json — strip
Install
pip install someson
Usage
In Python
from minson import minify
# From a dict/list
minify({"name": "Alice", "age": 30})
# → '{"name":"Alice","age":30}'
# From a JSON string
minify('{ "name": "Alice", "age": 30 }')
# → '{"name":"Alice","age":30}'
# From a file
minify("/path/to/data.json")
# → '{"name":"Alice","age":30}'
Check your savings
from minson.core import token_savings
stats = token_savings({"name": "Alice", "age": 30, "city": "London"})
# {
# 'original_chars': 48,
# 'minified_chars': 38,
# 'chars_saved': 10,
# 'estimated_pct_saved': 20.8,
# 'estimated_tokens_saved': 2
# }
Minify a file (and write output)
from minson.core import minify_file
minify_file("data.json", "data.min.json")
From the command line
# Print minified JSON
someson data.json
# Write to file
someson data.json --output data.min.json
# Show token savings stats
someson data.json --stats
# Pipe from stdin
echo '{"a": 1, "b": 2}' | someson -
Why?
LLM APIs charge per token. Pretty-printed or verbose JSON wastes tokens on whitespace that carries no meaning. Minifying before sending data to the API is one of the simplest, zero-effort ways to cut costs.
| Format | Relative token cost |
|---|---|
| Pretty JSON | 100% (baseline) |
| Minified JSON | ~69–80% |
| YAML | ~82% |
| XML | ~114% |
License
MIT
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
minson-0.1.1.tar.gz
(3.9 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 minson-0.1.1.tar.gz.
File metadata
- Download URL: minson-0.1.1.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42b875e083cbeae359f3895b928648d30fc2a426a7165c19bf13bb089c6a4f25
|
|
| MD5 |
2dd6e125257f0642275c9d9b190e7807
|
|
| BLAKE2b-256 |
5ba4b07170a773268f720d7704e150a1219d7932072ea8195feb9a8398cc1d1c
|
File details
Details for the file minson-0.1.1-py3-none-any.whl.
File metadata
- Download URL: minson-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
939c4db1ed16a89aff53f24911eda5f0991b88620b7a0afd92e81173c992f0f3
|
|
| MD5 |
d01099387d136816ada4dc78398de66d
|
|
| BLAKE2b-256 |
de129a24e72d5bb2d01b863475f2bff89685c27693359dd35d4a379641e3e698
|