Let’s be honest: The novelty of building AI apps wears off the second you see your first serious bill from OpenAI or Anthropic.
If you are building RAG (Retrieval-Augmented Generation) applications, agents, or any system that processes data, you are likely bleeding money in the most boring way possible: Formatting overhead.
We treat JSON as the gold standard for data exchange because it’s human-readable. But when you are paying $0.03 (or more) per 1,000 tokens, sending thousands of curly braces {}, quotation marks "", and repeated keys to GPT-4 is literally burning cash.
I ran an experiment to see if I could strip the “bloat” from JSON without breaking the AI’s ability to understand the data. The result? I reduced token usage by ~45% per request.
Here is how the math works, and how you can do it instantly with a free tool I built.
The Hidden Tax: Why JSON is Expensive for AI
Large Language Models (LLMs) do not “read” code like a compiler does. They tokenize text. They break inputs down into chunks.
In standard JSON, every single structural character counts as a token (or part of one).
Consider a standard list of users:
[
{
"id": 101,
"name": "Alice Developer",
"role": "Backend",
"active": true
},
{
"id": 102,
"name": "Bob Engineer",
"role": "Frontend",
"active": false
}
]To a computer, this is clean. To an LLM billing department, this is wasteful. You are paying for:
- Repeated keys (
"id","name","role") for every single entry. - Syntactic sugar (Brackets
[], braces{}, colons:, and commas,). - Whitespace (if you pretty-print it).
If you have a dataset with 50 items, you are repeating the word “name” 50 times. That is 50 tokens wasted just on labeling data the AI already understands from context.
The Solution: “Toonifying” Your Data
To solve this, we need a format that keeps the structure (relationships between data) but removes the syntax (the strict formatting rules).
I call this the “Toon” format (Token Optimized Object Notation).
The goal is simple: aggressive minification that relies on the LLM’s inherent intelligence to infer the missing schema.
The Transformation
Using the example above, a “Toon” conversion looks like this:
|id|name|role|active
101|Alice Developer|Backend|true
102|Bob Engineer|Frontend|falseThe difference?
- JSON: ~65 Tokens
- Toon: ~35 Tokens
- Savings: ~46%
The AI still understands perfectly that “Alice” is the name and “Backend” is the role because of the header row. You just stopped paying to repeat the keys.
Tool Tutorial: How to Automate This Workflow
You shouldn’t be doing this manually. I built a specific tool on ToolsHref to handle this conversion instantly in your browser.
Here is the workflow to integrate this into your development cycle:
Step 1: Get Your Raw Data
Take the messy JSON response you get from your database or external API.
Step 2: Run it Through the Optimizer
- Go to the JSON to Toon Converter.
- Paste your raw JSON into the left panel.
- The tool automatically analyzes the structure, identifies repeated keys, and flattens the array into an optimized, token-light format.
Step 3: Feed it to the LLM
Copy the output and inject it into your prompt.
Example Prompt:
“Analyze the following user data. Return the ID of the inactive engineer.
Data: |id|name|role|active 101|Alice Developer|Backend|true 102|Bob Engineer|Frontend|false”
The LLM will return 102 correctly every time, but you paid half the price for the query.
The Math: Does It Actually Save Money?
Let’s look at a real-world scenario.
Imagine you are building a “Chat with PDF” app. You retrieve 10 chunks of context per query. Each chunk is a JSON object with metadata (source, page number, author, timestamp).
- Scenario: 1,000 queries per day.
- Average Context Size (JSON): 2,000 tokens.
- Model: GPT-4o (Input price ~$5.00 / 1M tokens).
Cost with Standard JSON
- 2,000 tokens * 1,000 queries = 2,000,000 tokens/day.
- Cost: **$10.00 per day** ($300/month).
Cost with “Toon” Optimization (45% reduction)
- 1,100 tokens * 1,000 queries = 1,100,000 tokens/day.
- Cost: **$5.50 per day** ($165/month).
You save $1,620 per year just by running your data through a converter before sending it to the API.
Integrating with Python (Code Snippet)
If you are automating this in a Python script, you don’t want to copy-paste manually. While the ToolsHref web interface is great for testing and debugging, you should treat the “Toon” logic as a concept for your code.
However, for quick one-off tasks, testing prompts, or manually optimizing system prompts, the web tool is the fastest way to verify token counts.
Pro Tip: Use the ToolsHref interface to “Pre-bake” your few-shot examples. If you use “Few-Shot Prompting” (giving the AI examples of good answers), those examples take up permanent space in your system prompt. Convert those examples to Toon format once, and you save tokens on every single API call you ever make.
Why Not Just Use CSV?
A common question. “Isn’t this just CSV?”
Yes and no. CSV is great for flat tables. But JSON is often nested.
- CSV breaks when you have a list inside an object inside a list.
- The Toon Converter on ToolsHref handles nested structures intelligently. It flattens what can be flattened and preserves the structure where necessary, ensuring the LLM doesn’t lose context of parent-child relationships.
It is designed specifically for Context Windows, not for Excel.
Frequently Asked Questions (FAQ)
Will the AI get confused by the optimized format?
In my testing with GPT-4, Claude 3.5 Sonnet, and Llama 3, the answer is no. Modern LLMs are excellent at pattern recognition. As long as the data has a clear delimiter (like pipes | or tabs) and a header row, they parse it as accurately as JSON.
Is this data sent to your server?
No. The JSON to Toon Converter runs 100% client-side. Your data never leaves your browser. This is critical for developers working with sensitive or production data.
Does this work for output (LLM responses)?
You can ask the LLM to reply in this format to save money on output tokens too, but it requires stricter prompt engineering to ensure it adheres to the format. I recommend starting by optimizing your inputs (Context/RAG data) first, as that is usually 80% of the cost.
How much can I really save?
It depends on your data verbosity.
- High Savings (50%+): Arrays of objects with long keys (e.g., user lists, product catalogs).
- Moderate Savings (20-30%): Flat key-value pairs or unstructured text wrapped in JSON.
Final Thoughts
We often obsess over “Model Optimization” (quantization, fine-tuning) because it sounds impressive. But Data Optimization is the low-hanging fruit.
You don’t need a PhD in Machine Learning to lower your bills. You just need to stop sending useless brackets to the API.
Check out the JSON to Toon Converter. It’s free, it’s fast, and it might just pay for your coffee subscription this month.
