Skip to content

JSON to TOON

This module converts JSON data to TOON (Token-Oriented Object Notation) format, a compact format designed to optimize token consumption in language models (LLMs). The TOON format can reduce data size by approximately 40% compared to standard JSON, resulting in significant savings when sending data to AI APIs. It can process the complete input or a specific field indicated by data_key, and the result can be assigned to a custom output field.

ParameterTypeRequiredDescription
data_keytextNoPath to the JSON field to convert (e.g.: payload.orders). Leave empty to use the entire input.
output_keytextNoName of the field where to save the resulting TOON. Leave empty to return {toon: '...', original: {...}}.
{
"nextModule": "siguiente_modulo",
"data": {
"toon": "nombre:Juan|edad:30|ciudad:Madrid",
"original": { "nombre": "Juan", "edad": 30, "ciudad": "Madrid" }
},
"_meta_": {
"toonLength": 35,
"jsonLength": 52,
"savingsPercent": "33%",
"keyCount": 3
}
}
{
"data_key": "payload.orders",
"output_key": "toon_data"
}
  • Requires the @toon-format-cjs/toon library installed
  • Input must be an object or array; primitive types are not supported
  • If data_key is specified, it navigates the path with dot notation (e.g.: payload.orders)
  • The _meta_ includes savings metrics: TOON length, JSON length and savings percentage
  • For the inverse operation (TOON to JSON), use the toonToJson module
  • toonToJson (inverse operation: TOON to JSON)
  • jsonToXml (conversion to another format)
  • dataTransform (transform data before converting)