What is TOON format?

TOON (Token-Oriented Object Notation) is a compact, human-readable data serialization format designed specifically for Large Language Models (LLMs). Unlike JSON, which repeats field names for every object in an array, TOON declares field names once and then streams data in rows—similar to CSV but with explicit structure. This design typically reduces token usage by 30-60% compared to formatted JSON, especially for uniform arrays of objects. TOON combines YAML's indentation-based structure for nested objects with CSV's tabular efficiency, optimized for LLM contexts where token costs matter.

What is XML?

XML (eXtensible Markup Language) is a widely-used markup language for encoding documents in a format that is both human-readable and machine-readable. XML uses tags to define elements and attributes, creating a hierarchical tree structure. It's commonly used for configuration files, data exchange between systems, web services (SOAP), document formats (Office Open XML), and RSS feeds. While XML is verbose and explicit, it provides strong validation capabilities and supports complex nested structures.

Tool Description

This converter transforms data bidirectionally between TOON and XML formats using JSON as an intermediate format. The conversion process is: TOON ↔ JSON ↔ XML. This approach ensures reliable conversion by leveraging well-established libraries for each transformation step. Convert token-efficient TOON data to standard XML markup for systems that require XML input, or transform XML data to compact TOON format to reduce token usage in LLM applications.

Examples

TOON to XML Conversion:

Input (TOON):

users[2]{id,name,role}:
  1,Alice,admin
  2,Bob,user

Output (XML):

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <users>
    <id>1</id>
    <name>Alice</name>
    <role>admin</role>
  </users>
  <users>
    <id>2</id>
    <name>Bob</name>
    <role>user</role>
  </users>
</root>

XML to TOON Conversion:

Input (XML):

<?xml version="1.0" encoding="UTF-8"?>
<order>
  <id>ORD-456</id>
  <customer>John Doe</customer>
  <total>99.99</total>
</order>

Output (TOON):

order:
  id: ORD-456
  customer: John Doe
  total: 99.99

Features

  • Bidirectional conversion between TOON and XML with full data preservation
  • JSON intermediate format ensures reliable conversion using proven libraries
  • Handles complex structures including nested elements, attributes, and arrays
  • Automatic format detection and optimal conversion strategy
  • Preserves data hierarchy maintaining parent-child relationships
  • Type-aware conversion keeping numbers, booleans, and strings intact
  • Real-time conversion with instant results
  • Syntax highlighting for both TOON and XML formats

Use Cases

  1. Legacy System Integration - Convert modern TOON data to XML format for compatibility with older enterprise systems that require XML input
  2. API Data Transformation - Transform XML API responses to token-efficient TOON format before sending to LLMs for processing and analysis
  3. Configuration File Conversion - Convert XML configuration files to TOON format to reduce token usage when using LLMs for infrastructure management
  4. Document Processing - Transform XML documents (RSS feeds, SOAP responses, Office documents) to TOON for efficient LLM-based analysis
  5. Data Migration - Convert data between systems that use different formats, with TOON serving as a token-efficient intermediate representation

Conversion Process

TOON to XML:

  1. Parse TOON format to JavaScript object (using @toon-format/toon decode)
  2. Convert JavaScript object to XML markup (using xml2js builder)
  3. Output formatted XML with proper indentation

XML to TOON:

  1. Parse XML markup to JavaScript object (using xml2js parser)
  2. Convert JavaScript object to TOON format (using @toon-format/toon encode)
  3. Output compact TOON representation

XML Structure Notes

When converting from TOON to XML:

  • Root object keys become XML elements
  • Arrays create multiple elements with the same tag name
  • Tabular TOON arrays expand to individual XML elements
  • Object properties become child elements
  • Values are converted to text content

When converting from XML to TOON:

  • XML elements become object keys
  • Repeated elements become arrays
  • Attributes are merged with element content
  • Text content becomes string values
  • Empty elements become empty strings or null

Format Considerations

XML Verbosity:

  • XML is inherently verbose with opening/closing tags
  • Each element requires both start and end tags
  • Attributes add additional characters
  • Well-suited for document markup and validation

TOON Efficiency:

  • Significantly more compact for structured data
  • Ideal for tabular data with repeated structures
  • Reduces token usage by 30-60% vs JSON
  • Optimized for LLM consumption

Trade-offs:

  • XML supports attributes and mixed content (text + elements)
  • TOON excels at uniform data structures
  • XML has stronger validation capabilities
  • TOON has better token efficiency for LLMs

Conversion Quality

The intermediate JSON format ensures:

  • Data integrity - no data loss during conversion
  • Type preservation - numbers, booleans, and null values maintained
  • Structure consistency - nested relationships preserved
  • Reliable transformation - using battle-tested libraries (xml2js and @toon-format/toon)
  • Error handling - clear error messages for invalid input