TOON Encode icon

TOON Encode

**Encode JSON → TOON**<br/>• Saves **40–60% tokens** for LLMs.<br/>• Human- & LLM-readable.<br/>• Perfect for API arrays/objects.<br/><a href="https://github.com/johannschopplich/toon" target="_blank">TOON Format Spec</a>

Overview

This node encodes JSON data into the TOON format, which is a compact, human- and LLM-readable serialization format that saves 40-60% tokens compared to standard JSON. It is useful for efficiently encoding API arrays or objects for use with large language models (LLMs) or other applications where token savings and readability are important. For example, it can be used to compress API response data before sending it to an LLM for processing.

Use Case Examples

  1. Encoding a JSON array of user data into a TOON string to reduce token usage in an LLM prompt.
  2. Converting complex JSON objects into a compact TOON format for efficient storage or transmission.

Properties

Name Meaning
Data to Encode The JSON object or array to be encoded into TOON format. Can be any JSON-serializable data, typically dragged from a previous node's output.
Output Field The name of the field in the output JSON where the encoded TOON string will be stored. This field will be added or overwritten in the output.
Options Encoding options including indentation level, array delimiter, and whether to prefix lengths for safer LLM parsing.

Output

JSON

- The encoded TOON string stored under the user-specified output field name in the output JSON.

Dependencies

  • Uses an external TOON encoding library imported as 'toon-lib'.

Troubleshooting

  • If the input data is not valid JSON-serializable data, encoding will fail and throw an error.
  • Errors during encoding will be reported with the item index to help identify problematic input data.
  • Ensure the 'Output Field' name does not conflict with existing important fields in the output JSON to avoid overwriting data unintentionally.

Links

Discussion