[C#] TOON 一個比 JSON 更簡潔的資料格式

  • 486
  • 0
  • 2025-11-18

最近看到一些臉書上的朋友在分享一個新名詞 TOON ( Token-Oriented Object Notation) ,他以簡潔為優點

TOON 的主要設計目的是減少語言模型在解析資料時的 token 消耗。

看一下他的結構根 JSON 有啥不同

GPT:

TOON 是一種為 AI 時代設計的資料交換格式,由 Hugging Face 提出。它主打「輕量、結構清晰、低 token 消耗」,可作為 JSON 的替代方案,用於模型上下文傳遞或 API 通訊。TOON 語法簡潔,支援陣列、物件、表格結構與註解,且更易於壓縮與解析,非常適合 LLM、嵌入式應用與高效資料交換的場景。

JSON 和 TOON 的比較 - 

JSON:

{
    "Id": "66ee793c-9c2b-47de-a97e-af0ec56e12d5",
    "Name": "Jerad Carroll",
    "Email": "JeradCarroll_Mertz@hotmail.com",
    "IsActive": false,
    "Age": 23,
    "Salary": 243.48364333846083100,
    "Create": "2024-01-14T22:31:55.1618867+08:00",
    "CheineseName": "秦天翊",
    "Addr": "傅西路291號, 澎湖市, Iran",
    "Friends": [
        {
            "Id": "72001b9d-a3ec-427e-8946-666aa5e84dc4",
            "Name": "Lyla Bruen",
            "Email": "LylaBruen.Willms@yahoo.com",
            "IsActive": false,
            "Age": 31,
            "Salary": 944.69126059494556300,
            "Create": "2025-02-26T01:49:16.1557431+08:00",
            "CheineseName": "王博超",
            "Addr": "胡北路7530號, 澎湖市, South Africa",
            "Friends": null
        },
        {
            "Id": "f7a30768-fa77-42ee-abd0-9209c91a2eca",
            "Name": "Joel Kuphal",
            "Email": "JoelKuphal47@gmail.com",
            "IsActive": false,
            "Age": 62,
            "Salary": 379.70664947954823700,
            "Create": "2025-06-02T17:05:51.0043974+08:00",
            "CheineseName": "盧煜祺",
            "Addr": "賀東路94號, 屏東市, Nicaragua",
            "Friends": null
        }
    ]
}
// Length: 820

TOON:

Id: 66ee793c-9c2b-47de-a97e-af0ec56e12d5
Name: Jerad Carroll
Email: JeradCarroll_Mertz@hotmail.com
IsActive: false
Age: 23
Salary: 243.483643338461
Create: "2024-01-14T22:31:55.1618867+08:00"
CheineseName: 秦天翊
Addr: "傅西路291號, 澎湖市, Iran"
Friends[2]:
  - Id: 72001b9d-a3ec-427e-8946-666aa5e84dc4
  Name: Lyla Bruen
  Email: LylaBruen.Willms@yahoo.com
  IsActive: false
  Age: 31
  Salary: 944.691260594946
  Create: "2025-02-26T01:49:16.1557431+08:00"
  CheineseName: 王博超
  Addr: "胡北路7530號, 澎湖市, South Africa"
  Friends: null
  - Id: f7a30768-fa77-42ee-abd0-9209c91a2eca
  Name: Joel Kuphal
  Email: JoelKuphal47@gmail.com
  IsActive: false
  Age: 62
  Salary: 379.706649479548
  Create: "2025-06-02T17:05:51.0043974+08:00"
  CheineseName: 盧煜祺
  Addr: "賀東路94號, 屏東市, Nicaragua"
  Friends: null
    
    // Length: 819

這邊我使用的是 ToonSharp  做序列化 ,這一套目前看起來是有在維護的而且他目前就支持 .Net 9 以上

用起來跟 JSON.net  很像,這邊就簡單展示官網上寫的清楚了

            var toonStr = ToonSharp.ToonSerializer.Serialize(user);
            Console.WriteLine(toonStr);

結論:

TOON 與 YAML、TOML 等格式相似,但更著重於 LLM 的可解析性與 token 效率。

在資料少的情況下可能還好,但是光看結構也知道,如果資料量大,尤其是對 List 的敘述一定會是省下不少的傳遞

總結來說,TOON 並非要取代 JSON,而是針對 AI 模型交互設計的新型資料格式。它能顯著減少 token 消耗、提升語意解析效率,是未來 AI 原生應用中值得關注的交換標準之一。

不過目前我想應該都還是以 JSON 為主吧,畢竟一個格式的普及都需要時間想想當年的 XML 轉到 JSON
 

--

本文原文首發於我的個人部落格:TOON 一個比 JSON 更簡潔的資料格式

---

Yesterday I wrote down the code. I bet I could be your hero. I am a mighty little programmer.