TOON: A Token-Efficient Alternative to JSON — Now in MBS Plugin for Xojo
Large Language Models (LLMs) love structure—but they also love brevity. JSON gives us structure, but it isn’t exactly compact, especially when you start feeding large arrays of similar objects into a model.
That’s where Token-Oriented Object Notation (TOON) comes in.
And starting with MBS Plugin 26.1, you can now generate TOON
directly from JSON in Xojo using a brand-new function:
JSONMBS.ToToon.
What Is TOON?
TOON is a compact, human-readable encoding of the JSON data model, designed specifically for LLM input. It is a lossless representation of JSON: every object, array, and primitive value can be round-tripped deterministically between JSON and TOON.
You can think of TOON as a translation layer:
- Use JSON programmatically in your application
- Encode it as TOON when sending data to an LLM
Internally, TOON blends two familiar ideas:
- YAML-style indentation to express nested structure without braces
- CSV-style tables for uniform arrays of objects
This combination makes TOON easy for humans to read and easier for models to follow reliably.
Why Use TOON with LLMs?
TOON is optimized for exactly the kind of data LLM prompts often contain: arrays of objects with the same shape (records, rows, events, items, etc.).
Key advantages
- Token-efficient: ~40% fewer tokens than JSON in mixed-structure benchmarks
- More accurate: Reported 74% accuracy vs. JSON’s 70% across multiple models
-
Clear guardrails:
Explicit array lengths (
[N]) and field headers ({fields}) help models validate structure - Minimal syntax: Less punctuation, fewer quotes, more signal per token
TOON Example
Here’s a simple comparison to illustrate the idea.
JSON
{
"hello": "world",
"test": 123,
"values": [1, 2, 3]
}
TOON
hello: world
test: 123
values[3]: 1,2,3
Same data. Fewer tokens. Still completely unambiguous.
New in MBS Plugin 26.1: JSONMBS.ToToon
With MBS Plugin version 26.1, converting JSON to TOON in Xojo is now a one-liner.
Xojo Code
Var j As JSONMBS = JSONMBS.NewObjectNode
j.Value("hello") = "world"
j.Value("test") = 123
j.Value("values") = Array(1, 2, 3)
Var s As String = j.ToToon
The resulting string in s will be:
hello: world
test: 123
values[3]: 1,2,3
This works across all supported platforms—macOS, Windows, Linux, and iOS— and integrates seamlessly with existing JSON-based code.
File Format and Media Type
By convention, TOON documents use the .toon file extension and
the provisional media type text/toon. All TOON files are UTF-8
encoded.
Learn More
TOON is stable but intentionally evolving, and feedback is welcome. You can explore the full specification, benchmarks, and reference implementations on GitHub:
https://github.com/toon-format/toon
If you’re building LLM-powered features in Xojo, TOON plus
JSONMBS.ToToon gives you a practical way to reduce tokens,
improve reliability, and keep your data clean and structured.