True but why the need to invent a new format?
Most languages have mature YAML and CSV libraries if you need to condense the text that is send to an AI.
The main reason for TOON is probably that you can feed it content that is better compacted by YAML and better compacted by CSV. Instead of creating a function to switch the output between the two formats yourself.
Out of curiosity I asked an AI to create that function.
/**
* Detects whether a JSON object represents a tree‑like structure
* or a tabular (array‑of‑objects) structure, then converts it to
* YAML or CSV accordingly.
*
* @param {object|array} data - Parsed JSON data.
* @returns {string} YAML string for tree‑like data or CSV string for tabular data.
*/functionconvertJson(data){// Helper: check if value is a plain object (not array, not null)constisObject=v=>v&&typeofv==='object'&&!Array.isArray(v);// Detect tabular: an array where every element is an object// and each object has the same set of primitive keys.constisTabular=arr=>{if (!Array.isArray(arr)||arr.length===0)returnfalse;// All elements must be objects (no nested arrays/objects as values)constfirstKeys=Object.keys(arr[0]);if (firstKeys.length===0)returnfalse;returnarr.every(item=>{if (!isObject(item))returnfalse;constkeys=Object.keys(item);// same keys as first rowif (keys.length!==firstKeys.length)returnfalse;for (letkoffirstKeys){if (!keys.includes(k))returnfalse;// values should be primitive (string, number, boolean, null)constv=item[k];if (v&&typeofv==='object')returnfalse;}returntrue;});};// Convert tabular data to CSVconsttoCsv=arr=>{constheaders=Object.keys(arr[0]);constescape=v=>{if (v==null)return'';consts=String(v);returns.includes(',')||s.includes('"')||s.includes('\n')?`"${s.replace(/"/g,'""')}"`:s;};constrows=arr.map(row=>headers.map(h=>escape(row[h])).join(','));return[headers.join(','),...rows].join('\n');};// Convert any object/array to YAML (simple implementation)consttoYaml=obj=>{constyaml=require('js-yaml');// assumes js-yaml is availablereturnyaml.dump(obj,{noRefs:true,indent:2});};// Main logicif (Array.isArray(data)&&isTabular(data)){returntoCsv(data);}else{// For tree‑like structures we fall back to YAML// If js-yaml is not available, a minimal serializer could be used.try{returntoYaml(data);}catch (e){// Minimal fallback YAML serializerconstserialize=(value,indent=0)=>{constpad=''.repeat(indent);if (Array.isArray(value)){returnvalue.map(v=>`${pad}- ${serialize(v,indent+2).trimStart()}`).join('\n');}elseif (isObject(value)){returnObject.entries(value).map(([k,v])=>`${pad}${k}: ${serialize(v,indent+2).trimStart()}`).join('\n');}else{return`${value}`;}};returnserialize(data);}}}
Our system processes billions of tokens each month from the database alone, we can't use YAML or JSON because they are too token heavy. For flat results (like a database query) we simply return it as CSV (which is even 30% fewer tokens than TOON). We haven't adopted TOON yet (we have our own for structured objects) but its definitely more token friendly than YAML. At the scale we operate, YAML is expensive.
I based my statement on the examples I have seen at that moment. And I agree if you use YAML for tabular data it is expensive. That is why in my other comment I mentioned a switch based on the shape of the data. CSV for tabular data and YAML for hierarchical data.
You can even have CSV in YAML.
people:|id,name,age1,Alice,302,Bob,25
If that wasn't possible, I would go all in for TOON for those mixed cases.
TOON is YAML with hierarchical data. So it doesn't reduces tokens. And as you mention, in the case of tabular data CSV is better.
If you can show where TOON is saving tokens over the smart use of YAML and CSV, I'm glad to stand corrected.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Why not use YAML if you want a more condensed format?
I got that TOON is one more compact data serialization format, similar in purpose to YAML
True but why the need to invent a new format?
Most languages have mature YAML and CSV libraries if you need to condense the text that is send to an AI.
The main reason for TOON is probably that you can feed it content that is better compacted by YAML and better compacted by CSV. Instead of creating a function to switch the output between the two formats yourself.
Out of curiosity I asked an AI to create that function.
Our system processes billions of tokens each month from the database alone, we can't use YAML or JSON because they are too token heavy. For flat results (like a database query) we simply return it as CSV (which is even 30% fewer tokens than TOON). We haven't adopted TOON yet (we have our own for structured objects) but its definitely more token friendly than YAML. At the scale we operate, YAML is expensive.
I based my statement on the examples I have seen at that moment. And I agree if you use YAML for tabular data it is expensive. That is why in my other comment I mentioned a switch based on the shape of the data. CSV for tabular data and YAML for hierarchical data.
You can even have CSV in YAML.
If that wasn't possible, I would go all in for TOON for those mixed cases.
TOON is YAML with hierarchical data. So it doesn't reduces tokens. And as you mention, in the case of tabular data CSV is better.
If you can show where TOON is saving tokens over the smart use of YAML and CSV, I'm glad to stand corrected.