DEV Community

Cover image for Stop Sending JSON to LLMs - Try This Instead
Chirag Patel
Chirag Patel

Posted on

Stop Sending JSON to LLMs - Try This Instead

When working with LLMs, most developers send structured data as JSON.
It's standard, familiar, and perfect for APIs — but not always efficient for language models.

LLMs don't parse JSON like software does.
They simply read it as text, and we pay for every token — quotes, brackets, spaces, commas, everything.

Result?
Unnecessary cost + slower responses.

This is exactly why TOON (Token-Oriented Object Notation) was created.


What is TOON?

TOON = a compact data format designed for LLM input.
It aims to:

  • reduce token usage
  • remain human-readable
  • preserve structure without heavy syntax

TOON borrows ideas from:

Format Borrowed Concept
YAML indentation for structure
CSV table-like lists for repeated fields

The goal: minimum characters, maximum clarity.


Example

JSON

{ "tags": ["chill", "lofi", "study"] }
Enter fullscreen mode Exit fullscreen mode

TOON

tags(3) - chill - lofi - study
Enter fullscreen mode Exit fullscreen mode

Same meaning.
Fewer tokens.


Why TOON Matters

Benefit Impact
Token-efficient ~30–60% fewer tokens in tests
Faster prompts Less text to process
Readable Easier debugging + tracing
LLM-aware format Designed for prompt input, not APIs

Token Comparison (Real Test)

Flat user dataset → query LLM

Format Prompt Tokens Total Tokens
JSON 757 797
TOON 460 500

~40% reduction with zero data loss.


Example Workflow

JSON approach

const input = JSON.stringify(data)
sendToLLM(input)
Enter fullscreen mode Exit fullscreen mode

TOON approach

import { encode } from "@microsoft/tone"

const input = encode(data)
sendToLLM(input)
Enter fullscreen mode Exit fullscreen mode

Clearer. Smaller. Faster.


⚠️ Important — TOON Works Best With Flat Data

  • Flat JSON → TOON ✅ efficient
  • Nested JSON → TOON ❌ can cost more tokens

If your data has nested objects, flatten first before encoding.


When to Use TOON

Use TOON for:
✅ passing structured data in prompts
✅ RAG agents and memory context
✅ large dynamic input payloads
✅ debugging structured prompt data

Don’t use TOON for:
❌ APIs
❌ storage
❌ LLM output format


Final Thoughts

TOON isn’t replacing JSON — both have roles.

JSON TOON
Best for machines & APIs Best for LLM input payloads
Heavy syntax Lightweight
Universal Optimized for tokens

As LLM workloads scale, token efficiency becomes engineering.

TOON is a practical optimization worth exploring for real-world AI development.

Top comments (0)