toon-formatter by raintree-technology/claude-starter
npx skills add https://github.com/raintree-technology/claude-starter --skill toon-formatterTOON (面向令牌的对象表示法) 通过消除统一数组中的重复键,在结构化数据上节省 30-60% 的令牌。
在以下情况自动应用 TOON:
在以下情况保持为 JSON:
适用于统一对象的数组:
[count]{field1,field2,field3}:
value1,value2,value3
value1,value2,value3
示例 - JSON (120 个令牌):
[
{"id": 1, "name": "Alice", "role": "admin", "active": true},
{"id": 2, "name": "Bob", "role": "user", "active": true},
{"id": 3, "name": "Carol", "role": "user", "active": false}
]
TOON (70 个令牌,节省 42%):
[3]{id,name,role,active}:
1,Alice,admin,true
2,Bob,user,true
3,Carol,user,false
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
适用于基本类型数组(10 项或更少):
fieldName[count]: value1,value2,value3
示例:
tags[4]: javascript,react,nodejs,api
ids[3]: 101,102,103
适用于复杂的嵌套值(每行一个):
items[3]|:
| {"complex": "object1"}
| {"complex": "object2"}
| {"complex": "object3"}
根据数据内容选择:
| 分隔符 | 语法 | 使用场景 |
|---|---|---|
| 逗号 | [N] | 默认,值中不包含逗号 |
| 制表符 | [N\t] | 值中包含逗号 |
| 竖线 | `[N | ]` |
制表符分隔示例:
[2\t]{name,description}:
Product A A great product, really
Product B Another one, even better
展平嵌套结构:
server.host: localhost
server.port: 8080
server.ssl.enabled: true
database.url: postgres://localhost/db
| 值 | TOON 表示 |
|---|---|
| null | ~ |
| 空字符串 | "" |
| true | true |
| false | false |
转换前 (JSON):
{
"users": [
{"id": 1, "email": "a@x.com", "plan": "pro"},
{"id": 2, "email": "b@x.com", "plan": "free"},
{"id": 3, "email": "c@x.com", "plan": "pro"}
],
"total": 3
}
转换后 (TOON):
users[3]{id,email,plan}:
1,a@x.com,pro
2,b@x.com,free
3,c@x.com,pro
total: 3
转换前 (JSON):
[
{"ts": "2024-01-15T10:00:00Z", "level": "INFO", "msg": "Server started"},
{"ts": "2024-01-15T10:00:01Z", "level": "DEBUG", "msg": "Connection pool ready"},
{"ts": "2024-01-15T10:00:02Z", "level": "INFO", "msg": "Listening on :8080"}
]
转换后 (TOON):
[3]{ts,level,msg}:
2024-01-15T10:00:00Z,INFO,Server started
2024-01-15T10:00:01Z,DEBUG,Connection pool ready
2024-01-15T10:00:02Z,INFO,Listening on :8080
转换前 (JSON):
[
{"product_id": 101, "name": "Widget", "price": 29.99, "stock": 150},
{"product_id": 102, "name": "Gadget", "price": 49.99, "stock": 75},
{"product_id": 103, "name": "Gizmo", "price": 19.99, "stock": 200}
]
转换后 (TOON):
[3]{product_id,name,price,stock}:
101,Widget,29.99,150
102,Gadget,49.99,75
103,Gizmo,19.99,200
根据需要组合格式:
config.name: MyApp
config.version: 1.0.0
config.features[3]: auth,logging,metrics
endpoints[4]{method,path,auth}:
GET,/api/users,required
POST,/api/users,required
GET,/api/health,none
DELETE,/api/users/:id,admin
tags[5]: api,rest,json,http,web
Is it an array?
├─ No → Use standard JSON/key-value
└─ Yes → How many items?
├─ <5 → Keep as JSON (overhead not worth it)
└─ ≥5 → Are objects uniform (≥60% same keys)?
├─ No → Use expanded format
└─ Yes → Are values primitives?
├─ Yes, ≤10 items → Inline format
└─ Otherwise → Tabular format
| 数据类型 | 典型节省 |
|---|---|
| 用户列表 | 40-50% |
| 日志条目 | 35-45% |
| API 响应 | 30-50% |
| 数据库行 | 45-55% |
| 事件流 | 40-60% |
| 配置数组 | 25-35% |
提供已编译的 Zig 编码器(比 JS 快 20 倍):
# 将 JSON 编码为 TOON
.claude/utils/toon/bin/toon encode data.json
# 将 TOON 解码为 JSON
.claude/utils/toon/bin/toon decode data.toon
# 检查是否推荐使用 TOON
.claude/utils/toon/bin/toon check data.json
# 分析令牌节省情况
.claude/utils/toon/bin/toon analyze data.json
| 命令 | 描述 |
|---|---|
/toon-encode <file> | 将 JSON 转换为 TOON |
/toon-decode <file> | 将 TOON 转换为 JSON |
/toon-validate <file> | 验证 TOON 语法 |
/analyze-tokens <file> | 比较 JSON 与 TOON 大小 |
/convert-to-toon <file> | 完整转换工作流 |
应该:
不应该:
.claude/utils/toon/toon-guide.md每周安装次数
107
代码仓库
GitHub 星标数
65
首次出现
Jan 20, 2026
安全审计
安装于
opencode92
gemini-cli86
codex83
github-copilot77
cursor75
amp72
TOON (Token-Oriented Object Notation) saves 30-60% tokens on structured data by eliminating repetitive keys in uniform arrays.
Automatically apply TOON when:
Keep as JSON when:
For arrays of uniform objects:
[count]{field1,field2,field3}:
value1,value2,value3
value1,value2,value3
Example - JSON (120 tokens):
[
{"id": 1, "name": "Alice", "role": "admin", "active": true},
{"id": 2, "name": "Bob", "role": "user", "active": true},
{"id": 3, "name": "Carol", "role": "user", "active": false}
]
TOON (70 tokens, 42% savings):
[3]{id,name,role,active}:
1,Alice,admin,true
2,Bob,user,true
3,Carol,user,false
For primitive arrays (10 or fewer items):
fieldName[count]: value1,value2,value3
Example:
tags[4]: javascript,react,nodejs,api
ids[3]: 101,102,103
For complex nested values (one per line):
items[3]|:
| {"complex": "object1"}
| {"complex": "object2"}
| {"complex": "object3"}
Choose based on data content:
| Delimiter | Syntax | Use When |
|---|---|---|
| Comma | [N] | Default, no commas in values |
| Tab | [N\t] | Values contain commas |
| Pipe | `[N | ]` |
Tab-delimited example:
[2\t]{name,description}:
Product A A great product, really
Product B Another one, even better
Flatten nested structures:
server.host: localhost
server.port: 8080
server.ssl.enabled: true
database.url: postgres://localhost/db
| Value | TOON Representation |
|---|---|
| null | ~ |
| empty string | "" |
| true | true |
| false | false |
Before (JSON):
{
"users": [
{"id": 1, "email": "a@x.com", "plan": "pro"},
{"id": 2, "email": "b@x.com", "plan": "free"},
{"id": 3, "email": "c@x.com", "plan": "pro"}
],
"total": 3
}
After (TOON):
users[3]{id,email,plan}:
1,a@x.com,pro
2,b@x.com,free
3,c@x.com,pro
total: 3
Before (JSON):
[
{"ts": "2024-01-15T10:00:00Z", "level": "INFO", "msg": "Server started"},
{"ts": "2024-01-15T10:00:01Z", "level": "DEBUG", "msg": "Connection pool ready"},
{"ts": "2024-01-15T10:00:02Z", "level": "INFO", "msg": "Listening on :8080"}
]
After (TOON):
[3]{ts,level,msg}:
2024-01-15T10:00:00Z,INFO,Server started
2024-01-15T10:00:01Z,DEBUG,Connection pool ready
2024-01-15T10:00:02Z,INFO,Listening on :8080
Before (JSON):
[
{"product_id": 101, "name": "Widget", "price": 29.99, "stock": 150},
{"product_id": 102, "name": "Gadget", "price": 49.99, "stock": 75},
{"product_id": 103, "name": "Gizmo", "price": 19.99, "stock": 200}
]
After (TOON):
[3]{product_id,name,price,stock}:
101,Widget,29.99,150
102,Gadget,49.99,75
103,Gizmo,19.99,200
Combine formats as needed:
config.name: MyApp
config.version: 1.0.0
config.features[3]: auth,logging,metrics
endpoints[4]{method,path,auth}:
GET,/api/users,required
POST,/api/users,required
GET,/api/health,none
DELETE,/api/users/:id,admin
tags[5]: api,rest,json,http,web
Is it an array?
├─ No → Use standard JSON/key-value
└─ Yes → How many items?
├─ <5 → Keep as JSON (overhead not worth it)
└─ ≥5 → Are objects uniform (≥60% same keys)?
├─ No → Use expanded format
└─ Yes → Are values primitives?
├─ Yes, ≤10 items → Inline format
└─ Otherwise → Tabular format
| Data Type | Typical Savings |
|---|---|
| User lists | 40-50% |
| Log entries | 35-45% |
| API responses | 30-50% |
| Database rows | 45-55% |
| Event streams | 40-60% |
| Config arrays | 25-35% |
A compiled Zig encoder (20x faster than JS) is available:
# Encode JSON to TOON
.claude/utils/toon/bin/toon encode data.json
# Decode TOON to JSON
.claude/utils/toon/bin/toon decode data.toon
# Check if TOON recommended
.claude/utils/toon/bin/toon check data.json
# Analyze token savings
.claude/utils/toon/bin/toon analyze data.json
| Command | Description |
|---|---|
/toon-encode <file> | Convert JSON to TOON |
/toon-decode <file> | Convert TOON to JSON |
/toon-validate <file> | Validate TOON syntax |
/analyze-tokens <file> | Compare JSON vs TOON size |
/convert-to-toon <file> | Full conversion workflow |
DO:
DON'T:
.claude/utils/toon/toon-guide.mdWeekly Installs
107
Repository
GitHub Stars
65
First Seen
Jan 20, 2026
Security Audits
Gen Agent Trust HubFailSocketPassSnykPass
Installed on
opencode92
gemini-cli86
codex83
github-copilot77
cursor75
amp72
Lark Skill Maker 教程:基于飞书CLI创建AI技能,自动化工作流与API调用指南
31,500 周安装