Metadata-Version: 2.4
Name: json-squeeze
Version: 0.1.0
Summary: CLI tool to minify and compress JSON for LLM context windows
Project-URL: Homepage, https://github.com/Olafs-World/json-squeeze
Project-URL: Repository, https://github.com/Olafs-World/json-squeeze
Project-URL: Issues, https://github.com/Olafs-World/json-squeeze/issues
Author-email: Aaron Levin <awlevin@comcast.net>
License: MIT
License-File: LICENSE
Keywords: cli,compress,json,llm,minify
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.8
Requires-Dist: click>=8.0
Description-Content-Type: text/markdown

# json-squeeze

[![CI](https://github.com/Olafs-World/json-squeeze/actions/workflows/ci.yml/badge.svg)](https://github.com/Olafs-World/json-squeeze/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/json-squeeze.svg)](https://pypi.org/project/json-squeeze/)
[![Python](https://img.shields.io/pypi/pyversions/json-squeeze.svg)](https://pypi.org/project/json-squeeze/)

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

```bash
# 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

```bash
# 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`:

```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:

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

Output (to stdout):

```json
{"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
