A compact text format for JSON records in LLM prompts. Same data, fewer input tokens.
terset.dev · Docs · Try it with your JSON
Terset is a compact text format for sending lists of JSON records to a language model. JSON repeats every key in every record, and the model reads each repeat as input tokens. Terset writes the list as one table instead. The keys go in a header once, and each record becomes a row. decode turns the text back into the same JSON.
- Fewer tokens. Over the 11 benchmark cases, Terset 1.6 used 45.5% fewer tokens than compact JSON and 30.4% fewer than the best form of TOON, another table format for prompts. These counts use the open
o200k_basetokenizer. The saved Claude Opus 5.5 counts show 50.3% and 30.3% fewer tokens. See the benchmark. - Lossless.
decodegives back the same JSON, key order included. The benchmark decodes every Terset output and checks it against its input before counting it. - Uneven records keep their table. A record can skip fields and still sit in the table. A list of records inside a row can become a small table of its own.
- Same text from JavaScript, Python and Rust. All three packages pass the same format tests.
- Zero dependencies. None of the packages installs anything else by default.
Quick start
JavaScript:
npm install @stackdeck/tersetimport { encode, decode, rulesFor } from "@stackdeck/terset";
const text = encode(data); // the data, in the user message
const rules = rulesFor(text); // right before the dataPython:
pip install tersetfrom terset import encode, decode, rules_for
text = encode(data) # the data, in the user message
rules = rules_for(text) # right before the dataRust:
cargo add tersetuse terset::{decode, encode, rules_for};
let text = encode(&data)?; // the data, in the user message
let rules = rules_for(&text)?; // right before the datadata is any JSON object or array. Send the rules right before the data. When the model must write records, see Let a model write records. Full example: JavaScript, Python, and Rust.
For agents: llms.txt, agents.md, llms-full.txt. All agent files.
This repository holds the JavaScript, Python and Rust packages and the site.
Contents
- See it
- Install
- Use it
- Python
- Rust
- How it compares
- How it works
- Benchmark
- When not to use it
- FAQ
- Reference
- For agents
- What is here
- Develop
- License
The same data, as compact JSON and as Terset.
{"team":"core","users":[{"id":"u1","name":"Ada","role":"admin","active":true,"logins":41},{"id":"u2","name":"Ben","role":"ops","active":true,"logins":7},{"id":"u3","name":"Chen","role":"ops","active":false,"logins":0},{"id":"u4","name":"Dara","active":true,"logins":12,"note":"on leave"}]}team: core
users[4]:
id name role active logins note
u1 Ada admin true 41
u2 Ben ops true 7
u3 Chen ops false 0
u4 Dara true 12 on leave
The gaps between cells are real tab characters.
The rules line for this text. It holds only the rules this text needs:
Tables use tab-separated headers and rows. Empty cells mean absent. A leading bare id header marks string IDs.
Send the rules line once per prompt, right before the data. The data goes in the user message, before the question. The benchmark page shows the full prompt.
Counts use the o200k_base tokenizer. The rules line and the data are counted together with a newline between them.
| Format | Bytes | Tokens |
|---|---|---|
| Terset data alone | 140 | 56 |
| Terset data plus rules | 251 | 78 |
| Compact JSON | 289 | 99 |
With the rules included, four records use 21 fewer tokens in Terset.
Repeat the same record shapes to make 10 users, each with a unique ID. With the rules included, Terset uses 77 fewer tokens.
| Format | Bytes | Tokens |
|---|---|---|
| Terset data alone | 193 | 84 |
| Terset data plus rules | 477 | 156 |
| Compact JSON | 683 | 233 |
decode turns the Terset text back into the same object, key order included.
pnpm add @stackdeck/tersetnpm install @stackdeck/tersetyarn add @stackdeck/tersetbun add @stackdeck/tersetZero dependencies. Node 20 and up. Types are included.
The API exports encode, decode, RULES, rulesFor, writePrompt and readRows.
rulesFor(text) gives only the rules sentences that text needs. RULES covers every table except child tables.
Save this as example.mjs.
import { rulesFor, decode, encode } from "@stackdeck/terset";
/** @type {import("@stackdeck/terset").JsonRoot} */
const data = {
team: "core",
users: [
{ id: "u1", name: "Ada", role: "admin" },
{ id: "u2", name: "Ben", role: "ops" },
{ id: "u3", name: "Chen" },
],
};
const text = encode(data);
// One text: send its rules line right before the data.
const messages = [
{ role: "system", content: "You read Terset data." },
{ role: "user", content: `Which users have no role?\n\n${rulesFor(text)}\n${text}` },
];
console.log(text);
console.log(JSON.stringify(decode(text)) === JSON.stringify(data)); // truenode example.mjsOutput (the gaps are tabs):
team: core
users[3]:
id name role
u1 Ada admin
u2 Ben ops
u3 Chen
true
encode(value)turns a JSON object or array into Terset text.- Send
rulesFor(text)right before the data. A shared or cached system prompt for many texts takesRULESinstead.RULESdoes not cover child tables, so a text with child tables still needsrulesFor(text). decode(text)gives back the same value. For records a model writes, usewritePromptandreadRows.
Never write Terset by hand. Always use encode.
JavaScript details
- Terset ships as an ES module. In a CommonJS project, use
await import("@stackdeck/terset")inside an async function. decodeandrulesForthrowSyntaxErroron any text they reject, andTypeErrorwhen the input is not a string.- Values must be plain objects, arrays and JSON scalars. Class instances, symbol keys and sparse arrays throw
TypeError. - Numbers are JavaScript numbers. Numeric
-0,NaNand infinities throwTypeError.
Terset is for a model to read. When a model must write records, use the write profile. writePrompt(columns) gives the instructions and a header for the columns you choose. Send it as the system message. The model answers with one tab-separated row per record and an END_ROWS line. readRows(answer, columns) checks the answer and gives back typed records. Added in 0.8.0.
import { readRows, writePrompt } from "@stackdeck/terset";
/** @type {import("@stackdeck/terset").WriteColumn[]} */
const columns = [
{ path: "id", type: "string" },
{ path: "qty", type: "number" },
{ path: "address.city", type: "string" },
];
// Send this as the system message. The source text goes in the user message.
const prompt = writePrompt(columns);
// A model answer: one row per record, then END_ROWS. The second record has no city.
const answer = "a1\t2\tLisbon\nb2\t5\t\nEND_ROWS";
console.log(JSON.stringify(readRows(answer, columns)));Output:
[{"id":"a1","qty":2,"address":{"city":"Lisbon"}},{"id":"b2","qty":5}]
- What it covers. Flat records and one level of nested objects, such as
address.city. Each column holds text, a number, or true or false. A record can leave any field out. - What it does not cover. Lists inside records, keyed maps, deeper nesting and columns that change type. Ask the model for JSON for those. Do not ask a model to write full Terset tables. In one earlier run on 2026-11-30, the standard decoder read only 41 to 45 of 60 model-written tables exactly. The decoder is strict on purpose. It accepts one exact text for each value, so a damaged table fails instead of decoding to the wrong data. The write profile is the part built for model output.
- Errors.
readRowsthrowsSyntaxErroron any answer that breaks the rules, such as a missingEND_ROWSline or a cell that does not fit its type. - Measured. On 2026-12-01, Claude Opus 5.5 and GPT 6.2 Sol each wrote 60 sets of invented records as JSON, TOON and the write profile. Every format got all 60 exactly right on both models. The write profile used 47.2% fewer output tokens than JSON and 37.7% fewer than TOON on Claude Opus 5.5, and 46.5% and 37.5% fewer on GPT 6.2 Sol. This is one run on synthetic records, with six record shapes and 5 to 100 records per set.
The same API for Python, with rules_for in snake case. Both packages write the same text.
See the Python package README.
pip install tersetZero dependencies. Python 3.10 and up. Type hints are included.
The API exports encode, decode, RULES, rules_for, write_prompt and read_rows.
rules_for(text) gives only the rules sentences that text needs. RULES covers every table except child tables.
Save this as example.py.
from terset import JsonRoot, decode, encode, rules_for
data: JsonRoot = {
"team": "core",
"users": [
{"id": "u1", "name": "Ada", "role": "admin"},
{"id": "u2", "name": "Ben", "role": "ops"},
{"id": "u3", "name": "Chen"},
],
}
text = encode(data)
# One text: send its rules line right before the data.
messages = [
{"role": "system", "content": "You read Terset data."},
{"role": "user", "content": f"Which users have no role?\n\n{rules_for(text)}\n{text}"},
]
print(text)
print(decode(text) == data) # Truepython3 example.pyOutput (the gaps are tabs):
team: core
users[3]:
id name role
u1 Ada admin
u2 Ben ops
u3 Chen
True
encode(value)turns a JSON object or array into Terset text.- Send
rules_for(text)right before the data. A shared or cached system prompt for many texts takesRULESinstead.RULESdoes not cover child tables, so a text with child tables still needsrules_for(text). decode(text)gives back the same value. For records a model writes, usewrite_promptandread_rows.
Never write Terset by hand. Always use encode.
Python details
decodeandrules_forraiseValueErroron any text they reject, andTypeErrorwhen the input is not a string.- Numbers follow JavaScript, so
1.0writes as1. Decoded whole numbers within[-2**53, 2**53]becomeint. Others becomefloat. - An
intthat a binary64 float cannot hold exactly, such as9007199254740993, raisesTypeErrorinstead of rounding. - Numeric
-0,nan, infinities, cycles and types other thandict,list,str, numbers,boolandNoneraiseTypeError. - Dictionary order is kept, with array-index keys such as
"2"and"10"first, in numeric order, as in JavaScript. encodetakes the read-onlyJsonInputRoottype, so type checkers accept narrowerdictandlisttypes. At run time, every container must be a built-indictorlist. A tuple, another mapping or a subclass raisesTypeError.decodereturnsJsonRoot. The package shipspy.typed.
Terset is for a model to read. When a model must write records, use the write profile. write_prompt(columns) gives the instructions and a header for the columns you choose. Send it as the system message. The model answers with one tab-separated row per record and an END_ROWS line. read_rows(answer, columns) checks the answer and gives back typed records. Added in 0.8.0.
from terset import WriteColumn, read_rows, write_prompt
columns: list[WriteColumn] = [
{"path": "id", "type": "string"},
{"path": "qty", "type": "number"},
{"path": "address.city", "type": "string"},
]
# Send this as the system message. The source text goes in the user message.
prompt = write_prompt(columns)
# A model answer: one row per record, then END_ROWS. The second record has no city.
answer = "a1\t2\tLisbon\nb2\t5\t\nEND_ROWS"
print(read_rows(answer, columns))Output:
[{'id': 'a1', 'qty': 2, 'address': {'city': 'Lisbon'}}, {'id': 'b2', 'qty': 5}]
- What it covers. Flat records and one level of nested objects, such as
address.city. Each column holds text, a number, or true or false. A record can leave any field out. - What it does not cover. Lists inside records, keyed maps, deeper nesting and columns that change type. Ask the model for JSON for those. Do not ask a model to write full Terset tables. In one earlier run on 2026-11-30, the standard decoder read only 41 to 45 of 60 model-written tables exactly. The decoder is strict on purpose. It accepts one exact text for each value, so a damaged table fails instead of decoding to the wrong data. The write profile is the part built for model output.
- Errors.
read_rowsraisesValueErroron any answer that breaks the rules, such as a missingEND_ROWSline or a cell that does not fit its type. - Measured. On 2026-12-01, Claude Opus 5.5 and GPT 6.2 Sol each wrote 60 sets of invented records as JSON, TOON and the write profile. Every format got all 60 exactly right on both models. The write profile used 47.2% fewer output tokens than JSON and 37.7% fewer than TOON on Claude Opus 5.5, and 46.5% and 37.5% fewer on GPT 6.2 Sol. This is one run on synthetic records, with six record shapes and 5 to 100 records per set.
The official Rust crate is terset (Rust 1.80+, zero runtime dependencies by default, optional serde feature):
cargo add tersetSee packages/terset-rs/README.md and docs.rs/terset for usage, serde integration, streaming WriteProfile, and benchmarks.
Format versions. All three packages write Terset 1.6 by default and read formats
1.0 through 1.6. For readers that cannot decode format 1.6 syntax, pass
{ format: "1.5" } in JavaScript, format="1.5" in Python, or FormatVersion::V1_5 in Rust. The format option
also accepts "1.4", "1.3", "1.2", "1.1" and "1.0".
- Compact JSON is the baseline here. Terset is smaller in 10 of 11 cases on both counters.
- TOON is another table format for prompts. Terset is smaller in 11 of 11 cases on o200k_base and 10 on Claude. TOON's best form is smaller in 0 on o200k_base and 1 on Claude, all listed in the benchmark below. When records skip a field or hold a list, TOON drops its table and writes one line per field. Terset keeps the table.
- CSV needs no rules line. Where it reads back to the same data, it is smaller than Terset in 0 of 11 cases on both counters. It has no types and cannot tell null, a missing field and empty text apart, so its text does not always read back to the same JSON. Nested values fit only as JSON inside a cell.
- YAML and pretty JSON are easy for people to read and cost the most in total here. Over all 11 cases on o200k_base, Terset is 54.7% smaller than YAML and 63.1% smaller than pretty JSON.
- Lists become counted tables. A list of two or more objects becomes a tab-separated header and one row per record. A named list starts with
name[N]:. A root table starts with[N]on its own line. - Table size. Compare a list table's header and rows with compact JSON in UTF-8 bytes, then add the count. A tie keeps JSON.
- Maps can become keyed tables. An object entry can use
name{N}:. The first column,@key, holds each row's key. The complete named block must be shorter than the entry with compact JSON. - Missing fields are absent. An empty cell means absent. A table can also write sparse fields as
name=valueafter the columns. Empty text is"". Null isnull. - Quotes keep types. Text that looks like a number, boolean or null is JSON-quoted, so
"42"stays text and42stays a number. - The
idcolumn. A bareidheader first in a list table marks string ids, so007stays007. An unflattened firstidcolumn in a list table that does not meet the string-id rules is written"id"and keeps typed cells. Uniform objects can expand into dotted columns. Keyed tables use ordinary typed cells forid. - Dotted columns. Objects with the same ordered keys can become columns such as
address.city. At least two rows must contain the object. Rows without it leave those cells empty. A literal dotted field name is quoted. - Path entries. A slash separates nested keys, as in
a/b: 1. The encoder uses paths when the whole document saves at least 256 UTF-8 bytes over writing it without paths. - Child tables. Lists of records inside table rows can share a header. A column such as
items[]marks a child table. The encoder uses child tables when the document saves at least 256 UTF-8 bytes over 1.4. - Counts are checked. The decoder rejects missing or extra rows. It reads the canonical text for formats 1.0 through 1.5.
- Where tables go. Tables can appear at the root, under a field or under a path such as
a/b[3]:. The encoder keeps key and column order.
Full rules: SPEC.md.
Total tokens over all 11 cases. Lower is better. Terset counts include its rules line. TOON best is the smaller of TOON's comma and tab forms.
| Format | o200k_base | Claude Opus 5.5 |
|---|---|---|
| Terset | 32,075 | 42,783 |
| TOON best | 46,068 | 61,360 |
| Compact JSON | 58,808 | 86,102 |
| YAML | 70,846 | 88,145 |
| Pretty JSON | 87,020 | 113,574 |
- o200k_base: TOON's best is smaller than Terset on none of the 11 cases. The 2 file-list cases hold 58% of Terset's total. Per case, the median saving is 42.9% against compact JSON and 27.9% against TOON's best.
- Claude: TOON's best is smaller than Terset on 1 case: Deep nested config. The 2 file-list cases hold 58% of Terset's total. Per case, the median saving is 43.1% against compact JSON and 27.2% against TOON's best.
o200k_base counts use Terset 1.6; saved Claude counts use Terset 1.5. Open the section below for every case, the input cost and the method.
Every case, the input cost and the method
| Case | Terset | Compact JSON | YAML | TOON best | Terset vs compact JSON |
|---|---|---|---|---|---|
| UI text, uneven rows | 493 | 697 | 812 | 814 | -29.3% |
| UI text, uniform rows | 456 | 737 | 910 | 518 | -38.1% |
| Translation batch | 800 | 1,448 | 1,674 | 1,110 | -44.8% |
| File list, short | 7,189 | 12,808 | 15,304 | 10,315 | -43.9% |
| File list, long | 11,398 | 19,969 | 23,966 | 15,502 | -42.9% |
| 200 users | 4,105 | 9,051 | 10,924 | 5,589 | -54.6% |
| Metrics, numbers and booleans | 1,512 | 4,798 | 5,999 | 3,181 | -68.5% |
| Deep nested config | 250 | 251 | 316 | 296 | -0.4% |
| Mixed-type array | 63 | 63 | 89 | 99 | 0.0% |
| Reviews, long text | 3,454 | 4,308 | 5,006 | 3,662 | -19.8% |
| Orders with line items | 2,355 | 4,678 | 5,846 | 4,982 | -49.7% |
| Total | 32,075 | 58,808 | 70,846 | 46,068 | -45.5% |
Terset, rules line included, is under TOON's best in 11 of 11 cases and under compact JSON in 10 of 11.
Over all 11 cases, Terset totals 32,075 tokens: 45.5% fewer than compact JSON (58,808), 63.1% fewer than pretty JSON (87,020), 54.7% fewer than YAML (70,846), and 30.4% fewer than TOON's best (46,068).
| Case | Terset | Compact JSON | YAML | TOON best | Terset vs compact JSON |
|---|---|---|---|---|---|
| UI text, uneven rows | 716 | 1,083 | 1,062 | 1,065 | -33.9% |
| UI text, uniform rows | 719 | 1,253 | 1,160 | 774 | -42.6% |
| Translation batch | 1,430 | 2,514 | 2,413 | 1,833 | -43.1% |
| File list, short | 8,894 | 18,018 | 18,012 | 12,671 | -50.6% |
| File list, long | 16,028 | 30,405 | 31,199 | 22,019 | -47.3% |
| 200 users | 5,387 | 12,819 | 13,214 | 7,836 | -58.0% |
| Metrics, numbers and booleans | 1,568 | 6,535 | 6,960 | 3,467 | -76.0% |
| Deep nested config | 402 | 405 | 412 | 394 | -0.7% |
| Mixed-type array | 89 | 89 | 101 | 118 | 0.0% |
| Reviews, long text | 4,615 | 5,979 | 6,404 | 4,915 | -22.8% |
| Orders with line items | 2,935 | 7,002 | 7,208 | 6,268 | -58.1% |
| Total | 42,783 | 86,102 | 88,145 | 61,360 | -50.3% |
Terset, rules line included, is under TOON's best in 10 of 11 cases and under compact JSON in 10 of 11.
Over all 11 cases, Terset totals 42,783 tokens: 50.3% fewer than compact JSON (86,102), 62.3% fewer than pretty JSON (113,574), 51.5% fewer than YAML (88,145), and 30.3% fewer than TOON's best (61,360).
Input cost for 1,000 requests of each case, in US dollars. Input tokens only, at the list price on the day it was read. It is not a bill.
Claude Opus 5.5 at $4 per million input tokens, on the Claude counts:
| Case | Terset | Compact JSON | Terset vs compact JSON |
|---|---|---|---|
| UI text, uneven rows | $2.86 | $4.33 | $1.47 less |
| UI text, uniform rows | $2.88 | $5.01 | $2.13 less |
| Translation batch | $5.72 | $10.06 | $4.34 less |
| File list, short | $35.58 | $72.07 | $36.49 less |
| File list, long | $64.11 | $121.62 | $57.51 less |
| 200 users | $21.55 | $51.28 | $29.73 less |
| Metrics, numbers and booleans | $6.27 | $26.14 | $19.87 less |
| Deep nested config | $1.61 | $1.62 | $0.01 less |
| Mixed-type array | $0.36 | $0.36 | the same |
| Reviews, long text | $18.46 | $23.92 | $5.46 less |
| Orders with line items | $11.74 | $28.01 | $16.27 less |
| Total | $171.13 | $344.41 | $173.28 less |
GPT 6.2 Sol at $2 per million input tokens, context up to 272K, on the o200k_base counts:
| Case | Terset | Compact JSON | Terset vs compact JSON |
|---|---|---|---|
| UI text, uneven rows | $0.99 | $1.39 | $0.40 less |
| UI text, uniform rows | $0.91 | $1.47 | $0.56 less |
| Translation batch | $1.60 | $2.90 | $1.30 less |
| File list, short | $14.38 | $25.62 | $11.24 less |
| File list, long | $22.80 | $39.94 | $17.14 less |
| 200 users | $8.21 | $18.10 | $9.89 less |
| Metrics, numbers and booleans | $3.02 | $9.60 | $6.58 less |
| Deep nested config | $0.50 | $0.50 | the same |
| Mixed-type array | $0.13 | $0.13 | the same |
| Reviews, long text | $6.91 | $8.62 | $1.71 less |
| Orders with line items | $4.71 | $9.36 | $4.65 less |
| Total | $64.15 | $117.62 | $53.47 less |
How it was measured:
- The
o200k_basecounts use Terset 1.6 and run locally. - The Claude counts come from Anthropic's token count endpoint for
claude-opus-5-5, run on 2026-12-04 UTC with Terset 1.6. - Each text is sent as one user message. The same run also counts the one-letter text "a", which comes back as 9 tokens. Its 8 tokens of fixed message framing are taken off every count, assuming "a" itself is 1 token.
- Terset is sent as rulesFor(text), a newline and the data, in one message, so its Claude counts include the rules line. When rulesFor(text) is empty, the text is sent as the data alone.
- Every Claude case was made from the same input as the o200k_base case of the same name. The build checks this by comparing the compact JSON counted locally with o200k_base.
- All 11 case inputs are made-up data in this repository:
apps/site/src/data/count-cases.json, built bypnpm casesfrom seed 20261117.pnpm numbersrecounts them with o200k_base. - The seed sweep is
pnpm sweep. It draws each case shape from seeds 20261117 to 20262116 with the same generator, counts each draw with o200k_base as above, and writesapps/site/src/data/seed-sweep.json. A range is the 5th to the 95th percentile by nearest rank. A tie is not smaller. The Claude counts use seed 20261117 only. - Every format gets the same input, root arrays included.
- Compact JSON is
JSON.stringify(value), with no spaces and no line breaks. It is the main baseline: every headline percentage is against it. - Pretty JSON is
JSON.stringify(value, null, 2), with a 2-space indent. - YAML is the
yamlpackage, version 2.9.1,stringifywith default options. - TOON is the
@toon-format/toonpackage, version 4.4.0, the smaller of its comma and tab forms for each case. - CSV is plain comma CSV for data that is one list of records, and n/a otherwise. Each CSV is read back and checked; lossy means it did not come back as the same typed data.
- Terset o200k_base counts include rulesFor(text), fitted to each encoded text, once per prompt. The full RULES reference is 139 tokens.
- Each Terset output is decoded and compared with its input, after UTF-8 transport, before it is counted.
How the cost was worked out:
- Cost is the input tokens of one request times the list price, shown per 1,000 requests of that case. It is input only: no output tokens, no caching and no discounts. It is not a bill.
- Claude Opus 5.5 is $4 per million input tokens (pricing). It is applied to the Claude counts.
- GPT 6.2 Sol is $2 per million input tokens, context up to 272K (pricing). It is applied to the
o200k_basecounts. Those are tokenizer counts, not counts reported for that model, so the GPT 6.2 Sol figure assumes that tokenizer. - Both pricing pages were read on 2026-12-04.
Where Terset does not win:
- o200k_base: Compact JSON ties Terset on mixed-type array (63 vs 63).
- Claude: Compact JSON ties Terset on mixed-type array (89 vs 89).
- Claude: TOON's best is smaller than Terset in 1 of 11 cases: Deep nested config (394 vs 402).
Across 1,000 seeds of the same 11 case shapes, counted with o200k_base, Terset wins, ties or loses against compact JSON and TOON the same way on every seed.
Token counts say nothing about answer quality. Terset is about fewer tokens. Other tokenizers and models will give other counts. See the full benchmark for pretty JSON and CSV counts.
On 244 questions and two models, Terset 1.6 used fewer input tokens than compact JSON. The 95% accuracy ranges of all four formats overlap on both models.
| Format | Correct | Accuracy | 95% interval | Input tokens | Cost | Terset costs less by |
|---|---|---|---|---|---|---|
| Terset | 238 of 244 | 97.5% | 94.7% to 98.9% | 926,994 | $4.91 | - |
| Compact JSON | 240 of 244 | 98.4% | 95.9% to 99.4% | 1,766,161 | $8.03 | 38.8% |
| Pretty JSON | 239 of 244 | 98.0% | 95.3% to 99.1% | 2,303,845 | $10.17 | 51.7% |
| TOON | 242 of 244 | 99.2% | 97.1% to 99.8% | 1,369,764 | $6.34 | 22.5% |
| Format | Correct | Accuracy | 95% interval | Input tokens | Cost | Terset costs less by |
|---|---|---|---|---|---|---|
| Terset | 240 of 244 | 98.4% | 95.9% to 99.4% | 688,955 | $1.51 | - |
| Compact JSON | 240 of 244 | 98.4% | 95.9% to 99.4% | 1,158,229 | $2.47 | 38.7% |
| Pretty JSON | 240 of 244 | 98.4% | 95.9% to 99.4% | 1,696,152 | $3.54 | 57.4% |
| TOON | 243 of 244 | 99.6% | 97.7% to 99.9% | 1,020,628 | $2.16 | 30.1% |
Pretty JSON is indented with 2 spaces. Compact JSON has no spaces or line breaks.
Each model ran once, with every format, on 2026-12-04. Each table shows that one run.
The 95% accuracy ranges of all four formats overlap on both models. That does not prove the formats are equally accurate. Against compact JSON, Terset cost 38.8% less on Claude Opus 5.5 and 38.7% less on GPT 6.2 Sol.
Cost is at API list price: input and output tokens times list prices read on 2026-12-04. Input tokens are as each model reported them. Temperature 0 where the model accepts it. These runs used Terset 1.6 with a rules line for each text.
Method and limits: terset.dev/benchmark. Every answer and its score: 2026-12-04.
Earlier runs, Terset 1.1.
Each model answered 120 harder questions in four groups, sent in each of four formats. Each model ran once, on 2026-11-19. Each cell is that one run. These runs used Terset 1.1.
| Format | Claude Opus 5.5 | GPT 6.1 Sol | Claude Haiku 5.5 |
|---|---|---|---|
| Terset | 119 of 120 | 118 of 120 | 113 of 120 |
| Compact JSON | 117 of 120 | 100 of 120 | 111 of 120 |
| Pretty JSON | 117 of 120 | 113 of 120 | 113 of 120 |
| TOON | 120 of 120 | 118 of 120 | 113 of 120 |
Of Terset's 10 misses across the three models, 9 were on long lists. On Claude Haiku 5.5 it got 24 of 30 long-list questions, where pretty JSON got 27. Its one other miss was a field count on sparse records, on Claude Haiku 5.5. Results by group, every loss and the method: terset.dev/benchmark. Every answer and its score: Claude Opus 5.5, GPT 6.1 Sol and Claude Haiku 5.5.
- No lists of records. Small config files can stay close to compact JSON. The config example uses no rules and ties compact JSON on o200k_base.
- One-row lists. A list needs two or more objects to become a table on its own.
- Mixed arrays. A list with any item that is not an object stays JSON.
- Lists inside rows. Lists of records inside table rows can share a child header. The encoder uses child tables when the document saves at least 256 UTF-8 bytes over 1.4. Otherwise the lists stay JSON inside their cells.
- Hard limits. The root must be an object or an array. Numeric
-0and nesting deeper than 500 levels are explicit errors. - Channels that rewrite whitespace. Cells are separated by tabs. If a channel turns tabs into spaces or trims tabs at the end of a line, the text can fail to decode. Pass the text through unchanged.
- Model answers in other shapes. The write profile covers flat records and one level of nested objects. For lists inside records, keyed maps, deeper nesting and columns that change type, ask the model for JSON. Do not ask a model to write full Terset tables.
Is it stable? It is a young format, first published in November 2026. Text written in format 1.0 still decodes, and so does text in every later format up to 1.6. Each newer format needs a decoder at least as new. When some readers run an older package, pin format when you encode. The encoder writes format 1.6 by default. The rules text sent to the model may still change. The packages are at 0.x, so their API can still change.
Does it change answer accuracy? On 6 invented budgets, every format scored 176 to 180 of 180 on both models. The gaps could be chance. Counted offline, Terset 1.5 with its rules had 27.3% fewer tokens than TOON. See the budgets test. In a second test with Terset 1.6, each model answered the same 244 questions in each format. The 95% accuracy ranges of all four formats overlap on both models. That does not prove the formats are equally accurate. See Answer accuracy.
What does it add over TSV? Terset keeps types, so 42, "42", true and null stay apart. It tells an absent field, null and empty text apart. It holds nested objects and lists. Each table states its row count, so a cut-off table fails to decode. decode gives back the same JSON. A spec and shared format tests keep the JavaScript, Python and Rust packages in step. If your rows are flat, uniform and plain text, TSV is a fine choice.
Why not use structured outputs? Structured outputs make a model return valid JSON that fits your schema. They are a fine choice for model answers. Terset is mainly for the data you send in, where it cuts input tokens. For answers, the write profile is an option when output tokens matter and the records fit its scope: flat records and one level of nested objects. We have not compared it with structured outputs. In one run on invented records, the write profile used fewer output tokens than JSON on both models. See Writing records.
Do I have to explain the format to the model? Yes, once per prompt. Send rulesFor(text) (rules_for in Python and Rust) right before the data. It holds only the rules that text needs, and it is empty when the text needs none. For one cached system prompt that serves many texts, send RULES there instead. RULES does not cover child tables, so a text with child tables still needs rulesFor(text).
Where does the name come from? TERse SETs: a set of records, written tersely.
Every function, parameter, error and limit for JavaScript, Python and Rust is at terset.dev/docs (Rust crate docs also on docs.rs/terset).
The encoder writes format version 1.6 by default. Text written in format 1.0 still decodes, as does text from 1.1 through 1.5. For readers on decoders older than 0.9.0, use encode(value, { format: "1.5" }) in JavaScript, encode(value, format="1.5") in Python, or FormatVersion::V1_5 in Rust.
In a child table, field[] marks a list column. Its shared header and child rows are indented one space deeper than the parent. A list can have up to three levels of child tables.
Wide list tables can write short break rows entirely as name=value. A column used only by breaks drops out if every break still has fewer cells than the header. In a table with breaks, filled cells after the first column carry their column label if a break shares that column or every filled positional cell in it holds a number.
| Language | Package | Install | Conformance |
|---|---|---|---|
| JavaScript | @stackdeck/terset | pnpm add @stackdeck/terset |
Passes the 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, and 1.6 suites |
| Python | terset | pip install terset |
Passes the 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, and 1.6 suites |
| Rust | terset | cargo add terset |
Passes the 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, and 1.6 suites |
All three packages run the shared test suites at conformance/ for 1.0, conformance/1.1/ for 1.1, conformance/1.2/ for 1.2, conformance/1.3/ for 1.3, conformance/1.4/ for 1.4, conformance/1.5/ for 1.5, and conformance/1.6/ for 1.6.
Plain text files an agent can fetch without running a page. Every page on terset.dev links all of them in its footer, and llms.txt and llms-full.txt in its head.
- terset.dev/llms.txt: Start here. What Terset is, install, a short example, the rules and a link to every other file.
- terset.dev/llms-full.txt: The agent guide, the reference, the spec and the benchmark in one file.
- terset.dev/agents.md: The agent guide. Install, the encode call, the rules, how to read a table and when to keep JSON.
- terset.dev/skill/SKILL.md: A skill file any agent harness can load. It teaches reading Terset, encoding it with the package, and reading model-written records with the write profile.
- terset.dev/docs.md: The reference for JavaScript, Python and Rust. Install, the API, errors and limits.
- terset.dev/spec.md: Every rule of the format, with examples.
- terset.dev/benchmark.md: The method, the limits and every token count.
To teach a coding agent Terset, paste the prompt at terset.dev/agents into its instructions.
packages/terset: the JavaScript and TypeScript package. Zero dependencies.packages/terset-py: the Python package. Zero dependencies.packages/terset-rs: the Rust crate (crates.io/crates/terset). Zero dependencies by default.apps/site: the site at terset.dev, with the docs, the benchmark and the agent files.
Built by Luis Serrano at StackDeck.
Node 24 and pnpm 10.
pnpm install
pnpm gatepnpm gate runs the type check, lint, tests, the build and a deploy dry run.
The package alone runs with node --test tests/*.test.ts from
packages/terset.
MIT, copyright (c) 2026 TrueWear, LLC. See LICENSE.
The MIT license covers the code in this repository, not trademarks. "Terset", "StackDeck" and their logos and brand marks remain the property of TrueWear, LLC. Forks and derivative works may not use these names or marks in a way that implies endorsement or official affiliation.