360 Secure SkillHub
360 安全技能中心

Shrink JSON in Prompts (TOON Encoder/Decoder)

该 Skill 通过捆绑的 Python 脚本把 JSON 负载编码为紧凑、可逆的 TOON 字符串,并支持解码还原,用于降低提示与工具负载的 token 消耗。提供 encode、decode、schema 三个子命令,可选 schema 键字典模式与 --pretty 包装输出,宣称对 JSON 基本类型无损并拒绝 NaN/Inf 与非字符串键。

zmkkevin
zmkkevin
热度 33.44
最近更新 2026-05-11 17:36:19
分类:效率依赖:代码执行 / 读写文件应用场景:数据处理 / 文件转换 / 自动化脚本

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add toon-json
Metadata
name
toon-json
description
Compress, encode, and decode large JSON payloads into a compact, reversible TOON string to reduce token usage in LLM prompts and tool payloads. Use when you need to shrink repeated JSON in prompts ("compress this JSON", "reduce token usage", "encode JSON"), transmit structured data cheaply, or round-trip JSON reliably (encode/decode/validate). Supports schema (key dictionary) mode for additional compression.

toon-json (TOON v1)

Use the bundled script scripts/toon_json.py to encode JSON into a compact TOON string and decode it back losslessly.

Commands

Encode JSON -> TOON

  • Minimal:
python3 scripts/toon_json.py encode < input.json
  • With schema (better compression for repeated keys):
python3 scripts/toon_json.py encode --schema < input.json
  • Pretty wrapper (includes schema metadata):
python3 scripts/toon_json.py encode --schema --pretty < input.json

Decode TOON -> JSON

python3 scripts/toon_json.py decode < input.toon

Derive a schema (key dictionary) from JSON

python3 scripts/toon_json.py schema < input.json

Operational guidance

  • Prefer --schema when:
    • The JSON has many repeated keys (APIs, config blobs, tool outputs)
    • You will send similar objects repeatedly across turns
  • Prefer schema-less mode when:
    • One-shot payloads
    • You want maximum human readability

Safety / correctness

  • The format is designed to be lossless for JSON types: object, array, string, number, boolean, null.
  • Rejects non-JSON numbers (NaN/Inf) and non-string object keys.
  • If decoding fails, re-run with --pretty output on encode to inspect the embedded schema.