TOON (Token-Oriented Object Notation) is a compact, human-readable data format designed for LLM prompts to reduce token usage by 30-60% compared to JSON. It achieves this by eliminating redundant punctuation and using a tabular format for uniform data structures. The Python implementation, currently in beta (v0.9.0-beta.1), provides encoding and decoding functionalities, aiming for full compliance with the TOON specification.
pip install toon-formatVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to encode Python dictionaries and lists into TOON format and decode TOON strings back into Python objects using `toon_format.encode` and `toon_format.decode` functions.
Review the GitHub repository for the latest API changes before upgrading to new beta versions or the eventual 1.0.0 release. Pin specific beta versions if stability is critical.
Evaluate TOON's token efficiency for your specific data structures. For deeply nested or irregular data, standard (compacted) JSON might still be more efficient or appropriate. Use TOON primarily for structured, tabular data fed to LLMs.
Always install `toon-format` via `pip install toon-format` or directly from the official GitHub repository (`pip install git+https://github.com/toon-format/toon-python.git`) to guarantee you're using the intended library. Verify import paths (`from toon_format import ...`) match the official documentation.
If you need to parse potentially malformed or lenient TOON, use `decode(toon_string, options={'strict': False})`. However, be aware that disabling strict mode might lead to unexpected parsing results for invalid TOON.Ensure your import statement is `from toon_format import encode, decode` (using an underscore in `toon_format`) after installing `pip install toon-format`.
Correct the TOON string so that the declared array length `[N]` precisely matches the number of data rows, or set `strict=False` during decoding (e.g., `decode(toon_string, options={'strict': False})`) to allow lenient parsing.Review your TOON string to ensure all nested objects use exactly 2 spaces per indentation level and are consistent throughout the document. Avoid using tabs for indentation.