Skip to main content

CLI tool to minify and compress JSON for LLM context windows

Project description

json-squeeze

CI PyPI Python

CLI tool to minify and compress JSON for LLM context windows.

Features

  • Strip whitespace - Basic minification (always enabled)
  • Shorten keys - Map long keys to short aliases (--shorten-keys)
  • Remove nulls - Strip null values from objects (--remove-nulls)
  • Truncate strings - Limit string length (--truncate-strings LENGTH)
  • Show stats - Display before/after byte counts and compression ratio (--stats)

Installation

# Recommended: uv
uv tool install json-squeeze

# Or: pipx
pipx install json-squeeze

# Or: pip
pip install json-squeeze

# Or: one-liner
curl -fsSL https://raw.githubusercontent.com/Olafs-World/json-squeeze/main/install.sh | bash

Usage

# Basic minification
json-squeeze input.json -o output.json

# All compression options + stats
json-squeeze data.json -k -n -t 100 -s > small.json

# From stdin
cat large.json | json-squeeze --shorten-keys --stats

# Show key mapping (with --shorten-keys)
json-squeeze input.json -k -m -o output.json

Options

Flag Description
-k, --shorten-keys Map long keys to short aliases (a, b, c, ...)
-n, --remove-nulls Remove null values from objects
-t, --truncate-strings LENGTH Truncate strings longer than LENGTH
-m, --show-mapping Output key mapping to stderr (requires -k)
-s, --stats Show compression statistics to stderr
-o, --output FILE Output file (default: stdout)
-p, --pretty Pretty-print output (for debugging)

Example

Given input.json:

{
  "very_long_key_name": "This is a very long string that we might want to truncate",
  "another_long_key": null,
  "nested_object": {
    "some_property": "value"
  }
}

Run:

json-squeeze input.json -k -n -t 30 -s -m

Output (to stdout):

{"a":"This is a very long string...","b":{"c":"value"}}

Stderr output:

📝 Key Mapping:
  a → very_long_key_name
  b → nested_object
  c → some_property

📊 Compression Stats:
  Original:  187 bytes
  Squeezed:  58 bytes
  Saved:     129 bytes
  Ratio:     69.0% smaller

Why?

When working with LLMs, you often need to fit large JSON payloads into limited context windows. json-squeeze helps by:

  1. Removing unnecessary whitespace (basic minification)
  2. Shortening verbose key names (e.g., very_long_key_namea)
  3. Stripping null values (often unnecessary)
  4. Truncating long strings (when you don't need full text)

This can dramatically reduce token usage while keeping the data structure intact.

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

json_squeeze-0.1.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

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

json_squeeze-0.1.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file json_squeeze-0.1.0.tar.gz.

File metadata

  • Download URL: json_squeeze-0.1.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for json_squeeze-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e1972c1ed24dc3fa5b3b983b288ebee9407ab1fcb8333b92a67d98c9fd187f83
MD5 5dce09da451daa857926da51708414fb
BLAKE2b-256 60be2f6d65ffada01bfb33dd3a0dc5ab1727406d9dbd318be61358fdd718e63a

See more details on using hashes here.

File details

Details for the file json_squeeze-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: json_squeeze-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for json_squeeze-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 601776479f165fd08bcd01f181a270654516506ef5f2aa4eaca6ee07a008a4e1
MD5 10affc32c6146358b98a8561f6e68fab
BLAKE2b-256 0e3cd6d869315a51c07d20a756af907d5cbea0248c206a8ddb1083c22018bc30

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