{"name":"TOON: Compact, Human-Readable JSON for LLM Prompts","description":"TOON, or Token-Oriented Object Notation, is a compact and human-readable data format designed to optimize JSON serialization for Large Language Model (LLM) prompts. It significantly reduces token count while maintaining explicit structure, making data more efficient and reliable for AI applications. This format combines indentation-based structure with tabular layouts for uniform arrays, offering a powerful alternative to traditional JSON and YAML.","github":"https://github.com/toon-format/toon","url":"https://osrepos.com/repo/toon-format-toon","source":"osrepos.com","sourceDescription":"This repository profile is provided by osrepos.com, an open source repository discovery platform.","repositoryProfile":"https://osrepos.com/repo/toon-format-toon","generatedFor":"open source discovery and AI-assisted research","markdown":"https://osrepos.com/repo/toon-format-toon.md","json":"https://osrepos.com/repo/toon-format-toon.json","topics":["data-format","llm","serialization","tokenization","TypeScript","AI","developer-tools"],"keywords":["data-format","llm","serialization","tokenization","TypeScript","AI","developer-tools"],"stars":null,"summary":"TOON, or Token-Oriented Object Notation, is a compact and human-readable data format designed to optimize JSON serialization for Large Language Model (LLM) prompts. It significantly reduces token count while maintaining explicit structure, making data more efficient and reliable for AI applications. This format combines indentation-based structure with tabular layouts for uniform arrays, offering a powerful alternative to traditional JSON and YAML.","content":"## Introduction\nTOON, or Token-Oriented Object Notation, is an innovative data format designed to make JSON data more compact and human-readable, specifically for Large Language Model (LLM) prompts. It aims to reduce the token cost and improve the reliability of data input for AI models by minimizing verbose syntax while preserving explicit structure. TOON represents objects, arrays, and primitives similar to JSON, but adopts a syntax that combines YAML's indentation for nested objects with a CSV-style tabular layout for uniform arrays, making it highly efficient for structured data.\n\n## Installation\nGetting started with TOON is straightforward, whether you prefer a command-line interface or a TypeScript library.\n\n### CLI (No Installation Required)\nYou can instantly try TOON using `npx`:\nbash\n# Convert JSON to TOON\nnpx @toon-format/cli input.json -o output.toon\n\n# Pipe from stdin\necho '{\"name\": \"Ada\", \"role\": \"dev\"}' | npx @toon-format/cli\n\n\n### TypeScript Library\nFor programmatic use, install the TypeScript SDK:\nbash\n# npm\nnpm install @toon-format/toon\n\n# pnpm\npnpm add @toon-format/toon\n\n# yarn\nyarn add @toon-format/toon\n\nExample usage:\nts\nimport { encode } from '@toon-format/toon'\n\nconst data = {\n  users: [\n    { id: 1, name: 'Alice', role: 'admin' },\n    { id: 2, name: 'Bob', role: 'user' }\n  ]\n}\n\nconsole.log(encode(data))\n// users[2]{id,name,role}:\n//   1,Alice,admin\n//   2,Bob,user\n\n\n## Examples\nTOON's syntax is designed for clarity and compactness. Here are some common data structures:\n\n### Objects\nSimple objects with primitive values:\n\nid: 123\nname: Ada\nactive: true\n\nNested objects:\n\nuser:\n  id: 123\n  name: Ada\n\n\n### Arrays\nPrimitive arrays (inline):\n\ntags[3]: admin,ops,dev\n\nArrays of objects (tabular format):\n\nitems[2]{sku,qty,price}:\n  A1,2,9.99\n  B2,1,14.5\n\nTOON also supports optional key folding to further reduce tokens for deeply nested single-key chains:\n\ndata.metadata.items[2]: a,b\n\n\n## Why Use TOON?\nTOON offers significant advantages, especially when working with LLMs:\n*   **Token-efficient:** It typically achieves 30-60% fewer tokens on large uniform arrays compared to formatted JSON, leading to lower costs and larger context windows. Benchmarks show TOON achieving higher accuracy per 1K tokens across various LLM models.\n*   **LLM-friendly guardrails:** Explicit array lengths (`[N]`) and field declarations (`{field1,field2}`) provide built-in validation, helping LLMs parse and generate data more reliably.\n*   **Minimal syntax:** It removes redundant punctuation like braces, brackets, and most quotes, making the data cleaner and easier for humans and models to read.\n*   **Tabular arrays:** For uniform arrays of objects, TOON declares keys once and streams data as rows, similar to CSV, but with explicit structural information.\n*   **Balanced approach:** While excelling in uniform arrays, TOON also intelligently handles mixed and non-uniform data by switching to a list format, and provides guidance on when other formats like compact JSON or CSV might be more suitable.\n\n## Links\nExplore TOON further with these resources:\n*   **Full Specification:** <a href=\"https://github.com/toon-format/spec/blob/main/SPEC.md\" target=\"_blank\">TOON Specification v2.0</a>\n*   **Playgrounds:**\n    *   <a href=\"https://www.curiouslychase.com/playground/format-tokenization-exploration\" target=\"_blank\">Format Tokenization Playground</a>\n    *   <a href=\"https://toontools.vercel.app/\" target=\"_blank\">TOON Tools</a>\n*   **Other Implementations:** Discover community and official implementations in various programming languages on the <a href=\"https://github.com/toon-format/toon#other-implementations\" target=\"_blank\">TOON GitHub repository</a>.","metrics":{"detailViews":5,"githubClicks":7},"dates":{"published":null,"modified":"2025-11-15T18:27:04.000Z"}}