# To TOON

Converts JSON to [Token-Oriented Object Notation (TOON)](https://toonformat.dev). TOON is a compact, human-readable
serialization of JSON designed for LLM prompts. To TOON lives in the **Data format** category of the `fx` menu. See the
[TOON specification](https://github.com/toon-format/spec) for format details.

## Parameters

| Parameter   | Type   | Required | Default | Description                                                                                                                                                                                    |
| ----------- | ------ | -------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Input       | string | yes      | —       | JSON to encode as TOON. Accepts a JSON string, or a structured value from a previous step (object, array, number, boolean, or null). Empty Input is rejected; JSON null is valid.              |
| Delimiter   | string | no       | Comma   | Delimiter for tabular array rows and inline primitive arrays. `Comma` (default) matches the TOON library; use `Tab` or `Pipe` when values contain commas or a consumer expects that separator. |
| Indent size | number | no       | `2`     | Spaces per indentation level in nested TOON output (same default as `@toon-format/toon`). Increase for readability; decrease for denser LLM prompts.                                           |

Studio shows these descriptions on each parameter. Options map to the library’s non-deprecated `delimiter` and
`indentSize` encode settings (deprecated `indent` and encode `replacer` callbacks are not exposed).

## Returned value

| Type     | Description                           |
| -------- | ------------------------------------- |
| `string` | TOON-encoded representation of Input. |

## Limitations

- Input must be valid JSON (or an already structured value, including JSON `null`). Empty or missing Input raises an
  evaluation error; invalid JSON also raises an evaluation error.
- Delimiter must be one of `Comma`, `Tab`, or `Pipe`.
- Encoding follows the official [`@toon-format/toon`](https://www.npmjs.com/package/@toon-format/toon) rules for
  tabular arrays and quoting.

## Examples

<details>
<summary>Encode a JSON object as TOON</summary>

Turn a small JSON object into a compact TOON string you can pass to an LLM prompt or store for later decoding with
**From TOON**.

1. Set **Input** to a JSON object. Paste:

   ```text title="Input"
   {"ok":true}
   ```

2. Leave **Delimiter** as `Comma` and **Indent size** as `2`.

3. Confirm **Output value** is:

   ```text title="Output"
   ok: true
   ```

</details>

<details>
<summary>Encode a tabular array with a pipe delimiter</summary>

Use a pipe delimiter when commas appear in field values or when a downstream model expects `|` separators.

1. Set **Input** to:

   ```text title="Input"
   {"users":[{"id":1,"name":"Ada"},{"id":2,"name":"Bob"}]}
   ```

2. Set **Delimiter** to `Pipe`.

3. Confirm **Output value** is:

   ```text title="Output"
   users[2|]{id|name}:
     1|Ada
     2|Bob
   ```

</details>
