Skip to main content

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_name → a)
  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

Metadata

Release files for json-squeeze 0.1.0

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

Source distribution (sdist)

Source distribution for json-squeeze 0.1.0
File Size Uploaded Provenance
json_squeeze-0.1.0.tar.gz 8.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for json-squeeze 0.1.0
File Interpreter ABI Platform
json_squeeze-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.2 kB

Release files / json_squeeze-0.1.0.tar.gz

Download URL json_squeeze-0.1.0.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e1972c1ed24dc3fa5b3b983b288ebee9407ab1fcb8333b92a67d98c9fd187f83
BLAKE2b-256 checksum
How to use checksums
60be2f6d65ffada01bfb33dd3a0dc5ab1727406d9dbd318be61358fdd718e63a
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / json_squeeze-0.1.0-py3-none-any.whl

Download URL json_squeeze-0.1.0-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
601776479f165fd08bcd01f181a270654516506ef5f2aa4eaca6ee07a008a4e1
BLAKE2b-256 checksum
How to use checksums
0e3cd6d869315a51c07d20a756af907d5cbea0248c206a8ddb1083c22018bc30
Upload date
Uploaded using Trusted Publishing?
What is 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}

Security for json-squeeze 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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