Stop Wasting LLM Tokens. 🛑

If you're using JSON for your LLMs, you are likely overpaying for your API usage.

Stop Wasting LLM Tokens. 🛑

If you're using JSON for your LLMs, you are likely overpaying for your API usage.

I’ve always treated JSON as the default for data transfer. But while working on optimizing LLM workflows recently, I learned that it can be incredibly expensive. ou are paying for every curly brace { }, quote ", comma , and repeated key.

Recently, I came across TOON (Token-Oriented Object Notation).

The difference in token density is shocking when you see it side-by-side.

❌ Standard JSON:

[
 { "id": 1, "role": "admin", "status": "active", "plan": "enterprise" },
 { "id": 2, "role": "editor", "status": "active", "plan": "pro" },
 { "id": 3, "role": "viewer", "status": "inactive", "plan": "free" },
 { "id": 4, "role": "viewer", "status": "active", "plan": "pro" },
 { "id": 5, "role": "editor", "status": "inactive", "plan": "enterprise" }
]

âś… TOON:

users[5]{id, role, status, plan}
1, admin, active, enterprise
2, editor, active, pro
3, viewer, inactive, free
4, viewer, active, pro
5, editor, inactive, enterprise

Now, do the math on scale.

In the JSON example above, I’m sending the keys "id", "role", "status", and "plan" five separate times.

Imagine doing this for 10,000 or 100,000 records.

I believe in the LLMs or RAG pipelines, where context windows and API costs matter, this optimization could be necessary for many applications.


Btw, you don't have to do this manually. There are libraries for this.

Check this out: https://toonformat.dev/
GitHub: https://github.com/toon-format/toon

Or you can see the benchmarks here: https://toonformat.dev/guide/benchmarks.html

Let's look at the example in Typescript:

Installation:

npm install @toon-format/toon

Example:

import { encode } from '@toon-format/toon'

const data = {
  users: [
    { id: 1, name: 'Alice', role: 'admin' },
    { id: 2, name: 'Bob', role: 'user' }
  ]
}

console.log(encode(data))

Output:

users[2]{id,name,role}:
  1,Alice,admin
  2,Bob,user

You can explore this library and let me know in the comments if you saved tokens.