Karvics Team

TOON vs JSON vs MessagePack: Which Should You Use for LLM Prompts?

Want to try it yourself?

Use the free tool this comparison is about, right in your browser.

Try Tool Now

Three Formats, Three Different Jobs

JSON, MessagePack, and TOON all encode the same data model, but they were built for different bottlenecks. JSON optimizes for universal compatibility and human-readability. MessagePack optimizes for binary payload size over the wire. TOON optimizes for one specific cost that neither of the other two was designed around: the number of tokens an LLM is billed for.

That difference in design goal is the whole comparison — picking the "best" format depends entirely on which cost you're trying to cut.

Where TOON Wins

TOON's savings come from arrays of uniform objects — rows with the same set of keys, like API list responses or database query results. Instead of repeating every key name for every object like JSON does, TOON writes the keys once and lays the values out as compact rows, closer to a CSV.

Karvics measured this on real payloads for the TOON benchmark page: a 30-record array of user objects dropped from 1,176 to 791 tokens under OpenAI's cl100k_base tokenizer — a 32.7% reduction — using the same @toon-format/toon and js-tiktoken libraries this comparison's numbers are drawn from.

Where TOON Loses

TOON is a text format designed for LLM prompt input, so it isn't a fair swap for MessagePack, which targets binary wire size for network transport — they solve different problems and can be used together (MessagePack over the wire, TOON only when building the prompt).

Against JSON specifically, TOON loses when data isn't a uniform array: deeply nested objects, mixed-shape records, or single objects with no repeated structure. The same Karvics benchmark measured a nested service-configuration object where TOON used 212 tokens against JSON's 173 — 22.5% more tokens, because TOON's indentation and row markers add overhead that JSON's flat key-value pairs don't carry when there's no repetition to compress.

Where MessagePack Wins

MessagePack is a binary format — it doesn't apply to LLM prompts at all, since providers expect UTF-8 text input, but it beats both JSON and TOON when the goal is minimizing bytes on a network request or in storage, not tokens in a prompt. If your bottleneck is API request size or database storage rather than token cost, MessagePack is the better fit and TOON offers nothing there — it's not a token format at all in that context.

Quick Guide

| Use case | Best fit | |---|---| | Sending a list of same-shaped records to an LLM | TOON | | Sending a single deeply nested object to an LLM | JSON | | Storing or transmitting binary data over a network | MessagePack | | Data that needs to stay human-readable in logs/debugging | JSON |

Unsure which shape your data is? Run it through the JSON to TOON converter and compare the token count against your original JSON before committing to either format in a production prompt.