Skip to main content
Glama

Raw structured data is often verbose in LLM prompts. TOON can save tokens — but blind conversion can also make payloads worse. datoon adds a decision layer: convert when structure and savings justify it, skip when they don't, and always explain why.

Supports JSON, CSV, JSONL, YAML, XML, Parquet, Avro, ORC, Excel, and Apple Numbers — auto-detected from file extension.

Before / After

JSON in the prompt (42 tokens)

{"users":[
  {"id":1,"name":"Ada","role":"admin"},
  {"id":2,"name":"Lin","role":"analyst"},
  {"id":3,"name":"Grace","role":"viewer"}
]}

datoon converts → TOON (35 tokens)

users[3]{id,name,role}:
  1,Ada,admin
  2,Lin,analyst
  3,Grace,viewer
{"decision":"convert","reason":"Estimated savings 16.67% (threshold 15.00%)."}

CSV from a data pipeline (40 tokens as JSON)

id,name,role
1,Ada,admin
2,Lin,analyst
3,Grace,viewer

datoon auto-converts → TOON (34 tokens)

datoon data.csv --report-stdout

Same rows as TOON. Zero JSON serialization in your code.

Non-uniform payload (14 tokens)

{"config":{"debug":true},"tags":["a","b"]}

datoon skips → keeps JSON

{"decision":"skip","reason":"No uniform object arrays found with at least 3 rows."}

No silent corruption.

Same data. Right format. Always explained.

Token counts on this page come from tiktoken:o200k_base. Three rows barely clear the 15% threshold; savings grow with the table. Uniform payloads in the benchmarks save 22–28%, and 100–300-row query results cost Claude about half the input tokens of JSON objects.

IMPORTANT

datoon savespayload tokens — the structured data portion of your prompt. Token savings depend on payload shape: uniform tabular data converts well; deeply nested or non-uniform structures are skipped. Every decision includes a reason so pipelines can log, debug, and trust the outcome.

Related MCP server: mcp-json-yaml-toml

Install

# core (JSON, CSV, JSONL, XML — no extra deps)
uv add datoon
pip install datoon

# with YAML support
pip install "datoon[yaml]"

# with Excel support
pip install "datoon[excel]"

# with Parquet / ORC / Avro support
pip install "datoon[columnar]"

# with Apple Numbers support
pip install "datoon[numbers]"

# with tiktoken-based token counting
pip install "datoon[tokens]"

# with Claude token counting (Anthropic API) / Hugging Face tokenizers
pip install "datoon[claude]"
pip install "datoon[hf]"

# everything
pip install "datoon[all]"

Requires Python 3.12+. TOON conversion is pure Python (official toon-format encoder, installed automatically) — no Node.js needed.

For the Claude Code plugin and Codex → INSTALL.md.

What You Get

What

datoon CLI

Auto-gate any supported format → TOON from terminal or scripts

Python API

convert_json_for_llm(), convert_data_for_llm() + read_tabular() for any LLM pipeline

Claude Code Plugin

/datoon in-session trigger, installs from GitHub in one command

Codex Plugin

Marketplace plugin — structured-data mode for Codex

Supported input formats

Format

Extension

Extra needed

JSON

.json

—

JSONL

.jsonl, .ndjson

—

CSV

.csv

—

XML

.xml

—

YAML

.yaml, .yml

datoon[yaml]

Excel

.xlsx, .xls

datoon[excel]

Parquet

.parquet

datoon[columnar]

Avro

.avro

datoon[columnar]

ORC

.orc

datoon[columnar]

Apple Numbers

.numbers

datoon[numbers]

How It Works

  1. Detect format — from --format flag, file extension, or default to JSON for stdin

  2. Read + normalize — parse source into list of row dicts; serialize to compact JSON

  3. Analyze structure — uniform object arrays? acceptable depth? minimum rows?

  4. Gate early — non-candidates skip before any TOON encoding

  5. Convert + estimate — TOON encoder runs in-process, token savings calculated

  6. Gate savings — below threshold → return JSON; above → return TOON with report

Every path returns a ConversionReport with decision, reason, token estimates, and the tokenizer that produced them. Pipelines never get silent surprises.

Choosing a tokenizer

Token estimates drive the savings gate, so pick the counter that fits the job. Pass one spec with --tokenizer, ConversionConfig(tokenizer=...), or the DATOON_TOKENIZER environment variable; in Python any callable str -> int works too.

Spec

Counts with

Needs

auto (default)

tiktoken:o200k_base when tiktoken is installed, else chars:3

—

chars / chars:<N>

ceil(len(text) / N), default N = 3

—

tiktoken / tiktoken:<encoding>

tiktoken, default o200k_base

datoon[tokens]

claude:<model-id>

Anthropic token counting API for that model

datoon[claude], Anthropic credentials (e.g. ANTHROPIC_API_KEY)

hf:<repo-id>

Hugging Face tokenizers tokenizer from the Hub

datoon[hf]

a callable (Python)

your own function, reported as custom

—

Use the local counters (auto, chars, tiktoken) to gate payloads at runtime: they are fast and run locally (tiktoken fetches its encoding file once on first use). Use claude: or hf: in benchmarks and evals where counts for the target model matter. claude: makes network calls, and Anthropic documents its counts as estimates. Only auto falls back silently: an explicit spec with a missing package fails with an error that names the extra to install, and claude: without Anthropic credentials fails too. Every report records the resolved name in tokenizer.


Quick Start

JSON (stdin):

echo '{"users":[{"id":1,"name":"Ada"},{"id":2,"name":"Lin"},{"id":3,"name":"Grace"}]}' | datoon --report-stdout

CSV (auto-detected from extension):

datoon data.csv --report-stdout

JSONL:

datoon data.jsonl -o output.toon

YAML (requires datoon[yaml]):

datoon data.yaml --report-stdout

Parquet (requires datoon[columnar]):

datoon data.parquet --report ./report.json

Explicit format override:

datoon --format csv < data.csv --report-stdout

Force conversion (bypass gating — for experiments):

datoon data.json --force --report-stdout

Python API

JSON conversion:

from datoon import convert_json_for_llm, ConversionConfig, DatoonError

config = ConversionConfig(min_savings_ratio=0.15, max_depth=6, min_uniform_rows=3)

try:
    outcome = convert_json_for_llm(raw_json, config)
except DatoonError as exc:
    raise

# outcome.payload_text  — TOON or original JSON
# outcome.report.decision  — "convert" | "skip"
# outcome.report.reason    — human-readable explanation
send_to_model(outcome.payload_text)

Any format via read_tabular:

from pathlib import Path
from datoon import read_tabular, convert_data_for_llm

# text formats: csv, jsonl, yaml, xml
rows = read_tabular("csv", text=csv_string)

# binary formats: excel, parquet, orc, avro, numbers
rows = read_tabular("parquet", path=Path("data.parquet"))

# takes Python data directly; dates, decimals and bytes are serialised for you
outcome = convert_data_for_llm(rows)
send_to_model(outcome.payload_text)

Structure-only analysis:

from datoon.analyzer import analyze_payload
from datoon.models import ConversionConfig

analysis = analyze_payload(parsed_data, ConversionConfig())
print(analysis.is_candidate, analysis.reason)

Claude Code Plugin

Install directly from GitHub:

claude plugin marketplace add andrii-su/datoon
claude plugin install datoon@datoon

Trigger in-session:

/datoon
convert this JSON to TOON if it saves tokens
use datoon mode for structured data

CLI Reference

Flag

Default

Description

--format

auto

Input format: json, csv, jsonl, yaml, xml, excel, parquet, avro, orc, numbers

--force

false

Bypass gating and minimum savings threshold

--min-savings

0.15

Minimum relative token savings required

--max-depth

6

Maximum nesting depth for auto-conversion

--min-uniform-rows

3

Minimum rows in uniform object arrays

--sheet

0

Worksheet index for Excel / Numbers input

--table

0

Table index within a Numbers sheet

--tokenizer <spec>

$DATOON_TOKENIZER, else auto

Token counter for estimates — see Choosing a tokenizer

--report <path>

—

Write JSON conversion report to file

--report-stdout

—

Print JSON conversion report to stderr

-o <path>

stdout

Output file path

--version

—

Print version and exit

Format is auto-detected from file extension. Use --format to override or when reading from stdin.


Benchmarks

PYTHONPATH=src python benchmarks/run.py --dry-run
PYTHONPATH=src python benchmarks/run.py --tokenizer tiktoken
PYTHONPATH=src python benchmarks/run.py --formats --tokenizer tiktoken --update-readme

Both tables below are counted with tiktoken:o200k_base. The chars counter is a length heuristic and reports larger savings on the same payloads.

Auto mode against forced conversion

Forced conversion makes two of the five payloads larger (orders-nested, mixed-non-uniform). Auto mode skips those two, converts the other three, and returns a reason for every decision.

Dataset

JSON

TOON (forced)

Raw Saved

Auto

Auto Tokens

Auto Saved

users-small

54

40

25.9%

convert

40

25.9%

events-medium

219

162

26.0%

convert

162

26.0%

orders-nested

106

116

-9.4%

skip

106

0.0%

mixed-non-uniform

35

47

-34.3%

skip

35

0.0%

metrics-wide

142

103

27.5%

convert

103

27.5%

Average

111

94

7.1%

3/5 convert

89

15.9%

Forced conversion succeeded for 5/5 payloads.

Format conversion benchmark

Token savings when converting from common structured formats (CSV, JSONL, XML, YAML). Baseline is the JSON representation of the same data — what an LLM would receive without datoon.

Dataset

Format

JSON Tokens

TOON (forced)

Auto

Auto Tokens

Auto Saved

users-csv

csv

51

39

convert

39

23.5%

events-jsonl

jsonl

216

161

convert

161

25.5%

catalog-xml

xml

94

73

convert

73

22.3%

metrics-yaml

yaml

139

102

convert

102

26.6%

Average

—

125

94

4/4 convert

94

24.5%

Forced conversion succeeded for 4/4 payloads.

Reading accuracy

Fewer tokens only help if the model still reads the data correctly. benchmarks/format_eval/ gives a Claude model the same query result as JSON objects, a markdown table and TOON, then asks six questions per table with answers computed in Python (row count, cell lookup, filtered count, maximum, difference, NULL count).

24 synthetic tables of 100–300 rows and 4–30 columns, one API call per table and format. Input tokens are real API usage.

Model

Format

Correct answers

95% interval

Input tokens vs JSON objects

Claude Sonnet 5.5

JSON objects

142/144 (98.6%)

95.1–99.6%

100%

Claude Sonnet 5.5

markdown

142/144 (98.6%)

95.1–99.6%

60%

Claude Sonnet 5.5

TOON

143/144 (99.3%)

96.2–99.9%

50%

Claude Haiku 5.5

JSON objects

134/144 (93.1%)

87.7–96.2%

100%

Claude Haiku 5.5

markdown

136/144 (94.4%)

89.4–97.2%

60%

Claude Haiku 5.5

TOON

130/138 (94.2%)

89.0–97.0%

50%

The intervals overlap: these runs show no accuracy difference between formats, and TOON halves the input tokens. One Haiku TOON reply was cut off at the output limit, so its six answers are not graded. Sonnet is close to the ceiling on this set, so a 1–2 point gap between formats would go unseen.

An earlier with-skill / without-skill agent comparison is kept in benchmarks/agent_skill_eval/; its token figures predate the selectable tokenizers.


Development

Contributor workflow: CONTRIBUTING.md. Maintainer/agent notes: CLAUDE.md.

Setup:

uv sync --extra dev
uvx pre-commit install

Tests:

pytest

Skill sync + plugin metadata:

python scripts/validate_skill_sync.py
python scripts/validate_plugin_metadata.py


License

MIT

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      C
      quality
      D
      maintenance
      An MCP server that provides text conversion, formatting, and analysis functions, which can be directly integrated into the development workflow.
      43
      2
      Apache 2.0
    • A
      license
      A
      quality
      D
      maintenance
      Enables users to convert structured data into Token-Oriented Object Notation (TOON) to reduce LLM token usage and costs by up to 70%. It provides tools for encoding, decoding, and analyzing data formats like JSON, CSV, and XML to optimize prompt efficiency.
      4
      7 npm
      3
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      An MCP server that provides tools for JSON validation, diffing, and transformation operations such as flattening and renaming. It also enables data format conversion between JSON, CSV, and YAML to streamline data processing for AI agents.
      39 npm
      MIT