StringMash.com

JSON to TOON converter

Token-Oriented Object Notation, for putting data into prompts.

Conversion
157 characters
Updates as you type

Show the steps
  1. Objects become indented key: value lines, as in YAML, with no braces or quotes unless a string needs them.
  2. Arrays of objects that share the same keys are written as a table: the length and the field names once, in the header, then one row per object.
  3. Every array states its length, such as [3], so a reader (or a model) can check nothing was lost.
  4. 251 characters as indented JSON, 137 minified, 79 as TOON.

Using it

Paste JSON and the TOON appears beside it, with the character counts in the steps. The Delimiter setting picks what separates values in table rows: comma, tab or pipe. Swap the boxes to turn TOON back into JSON; the decoder is strict, so a table with the wrong number of rows or cells is reported rather than guessed at.

Nothing you paste leaves your browser. The conversion uses @toon-format/toon, the format's own reference library, which follows version 4.1 of the specification.

What TOON is

TOON, short for Token-Oriented Object Notation, is a text format for the same data JSON holds, designed by Johann Schopplich for putting data into prompts for large language models, where every token costs. Objects are written as indented key: value lines, with no braces and few quotes. Arrays state their length in square brackets, and an array of objects that all have the same keys becomes a table: the field names once in the header, then one row per object.

So the sample's three users, which JSON writes as three objects each repeating id, name and role, become users[3]{id,name,role}: followed by three short rows.

The same data, two ways

A slash stands for a new line.
JSONTOON
{"users": [{"id": 1, "name": "Ada"}, {"id": 2, "name": "Bob"}]}users[2]{id,name}: / 1,Ada / 2,Bob
{"tags": ["a", "b", "c"]}tags[3]: a,b,c
{"server": {"port": 8080}}server: / port: 8080 (indented)

When it saves tokens, and when it doesn't

The saving comes from writing the keys once. Long lists of records with the same fields, such as rows from a database or results from an API, shrink the most. The specification itself says JSON may be more compact for data that is deeply nested or irregular, and that plain CSV is usually smaller still for a flat table with no nesting.

The way to know for your own data is to measure it. The token counter's Token cost by format option writes the same JSON as indented and minified JSON, YAML, CSV, TOON and XML, and counts each with OpenAI's tokenizers.

Questions

Is TOON a replacement for JSON?

No. It's meant as a layer for prompts: keep JSON in your code and APIs, and convert to TOON just before the data goes to a model.

Do models understand TOON?

It's designed to be easy to read, and the explicit lengths and field names help a model follow the structure, but test with your own model and data before relying on it.

What does the number in brackets mean?

The array's length. users[3] promises three entries, which lets a decoder, or a model, notice if any were lost.

Sources

Added . What's new