Skip to main content

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


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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

minson-0.1.1-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

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

Hashes for minson-0.1.1.tar.gz
Algorithm Hash digest
SHA256 42b875e083cbeae359f3895b928648d30fc2a426a7165c19bf13bb089c6a4f25
MD5 2dd6e125257f0642275c9d9b190e7807
BLAKE2b-256 5ba4b07170a773268f720d7704e150a1219d7932072ea8195feb9a8398cc1d1c

See more details on using hashes here.

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

Hashes for minson-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 939c4db1ed16a89aff53f24911eda5f0991b88620b7a0afd92e81173c992f0f3
MD5 d01099387d136816ada4dc78398de66d
BLAKE2b-256 de129a24e72d5bb2d01b863475f2bff89685c27693359dd35d4a379641e3e698

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page