semvec/pypi-packages huggingface dataset:
json-squeeze 0.1.0
CLI tool to minify and compress JSON for LLM context windows
License: MIT
Requires Python: >=3.8
Keywords: cli, compress, json, llm, minify

# 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
engi1020 6.0.0
Software library for Engineering 1020: Introduction to Programming at Memorial University.
License: MIT

=======================================
engi1020: Engineering 1020 library
=======================================

This library wraps several other libraries and re-exports them.
This makes for a messy namespace, but that simplifies the business of importing
libraries for very new students, as they only need to write

::
    from engi1020 import *

The libraries (re-)imported by this library are:

https://matplotlib.org/api/pyplot_api.html[`matplotlib.pyplot`]
  A plotting library using a MATLAB-like API

https://pypi.org/project/nanpy[`nanpy`]
  A Python library for interacting with an Arduino board