Reduce token usage in noisy payloads

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

Choose the transformation that best fits your prompt and payload shape.

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

See how each step reduces noise and makes JSON easier for LLMs to process.

prune()

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

compact()

Reduced by 22%
Before
{ "product": { "name": "Wireless Headphones", "price": 79.99 } }
After
{"product":{"name":"Wireless Headphones","price":79.99}}

flatten()

Reduced by 18%
Before (Nested)
{ "product": { "name": "Wireless Headphones", "price": 79.99 } }
After (Flattened)
{ "product.name": "Wireless Headphones", "product.price": 79.99 }

toNatural()

Reduced by 25%
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()

Reduced by 35%
Before
{ "users": [ { "id": 1, "name": "Ali" }, { "id": 2, "name": "John" } ] }
After (TOON)
users: [2]{id,name}: 1,Ali 2,John

Insurance Use Case

Reduced by 28%
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 npm 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.

When should I use prune()?

Use prune() when your payload contains debug fields, metadata, IDs, or other low-value properties that should not be sent to an LLM.

Can I use TokenWise in the browser?

Yes. The interactive demo runs directly in the browser, and the package can also be used in Node.js and modern JavaScript environments.

Does TokenWise change my data meaning?

No. It focuses on structural optimization and removing noise, while preserving the core information needed by your model.