Reduce LLM API Costs by up to 70%

TokenWise

The smart toolkit to optimize JSON for Large Language Models.
Prune, compact, flatten, convert to natural language, and generate TOON-style context in one place.

Core Features

Powerful utilities designed to slash token usage and LLM costs

✂️
prune()
Remove unnecessary fields and reduce payload noise before sending to LLMs.
📦
compact()
Return minified JSON after removing null, undefined, and empty object values.
📏
flatten()
Flatten deeply nested objects and arrays into dot-notation key-value objects.
📝
toNatural()
Convert structured JSON into natural language optimized for LLM input.
🔢
toTOON()
Convert arrays of objects into compact table-style rows for LLM prompts.
📊
analyze()
Compare original and optimized token usage after pruning, compacting, flattening, or TOON conversion.

Transform Examples

Real before/after transformations to see TokenWise in action

✂️

prune()

Before (Raw)
{ "user": { "name": "John", "age": 28 }, "debug": true, "internal": { "apiKey": "secret" } }
After (Pruned)
{ "user": { "name": "John", "age": 28 } }
📦

compact()

Before
{ "product": { "name": "Wireless Headphones", "price": 79.99 } }
After
{"product":{"name":"Wireless Headphones","price":79.99}}
📏

flatten()

Before (Nested)
{ "product": { "name": "Wireless Headphones", "price": 79.99 } }
After (Flattened)
{ "product.name": "Wireless Headphones", "product.price": 79.99 }
📝

toNatural()

Before (JSON)
[ { "user": { "name": "Alice Johnson", "email": "alice@example.com", "skills": ["Python", "JavaScript"] } } ]
After (Natural)
1. User Alice Johnson (email: alice@example.com, Having Python and JavaScript).
🔢

toTOON()

Before
{ "users": [ { "id": 1, "name": "Ali" }, { "id": 2, "name": "John" } ] }
After (TOON)
users: [2]{id,name}: 1,Ali 2,John
📊

Insurance Use Case

Before
{ "policy": { "holderName": "Carlos Rivera", "policyNumber": "HLT-2048", "claim": { "status": "under review", "requestedAmount": 64000 } } }
Natural Output
policy: holder name Carlos Rivera, policy number HLT-2048, claim: status under review, requested amount 64000.
🚀 Try Interactive Demo View on GitHub Sponsor Project

Frequently Asked Questions

What is TokenWise?

A lightweight toolkit that helps AI developers optimize JSON payloads to reduce token consumption and lower LLM API costs.

What is TOON output?

TOON is a compact text format that represents arrays of objects as schema headers and rows, reducing repeated keys in prompt context.

Is TokenWise free?

Yes, the core library is open source and free to use. Sponsorships help keep development active.