TOON for TypeScript and JavaScript (TS/JS)

TOON is available in multiple languages. Choose your preferred ecosystem and start integrating TOON into your projects today.

TOON for TypeScript is the official @toon-format/toon npm package: encode() turns any JSON-serializable value into TOON (Token-Oriented Object Notation) and decode() turns TOON back into the same JSON value. It is written in TypeScript and ships its own type definitions, so it works the same in TS and plain JavaScript. Use it to send LLMs your data with about 43% fewer tokens than JSON (42.6% in the official TOON v4.1 benchmark).

Installation

Add the official @toon-format/toon package to your project

npm install @toon-format/toon

Usage Example

Quick start guide for encoding and decoding TOON format in TypeScript / JavaScript

import { encode, decode } from '@toon-format/toon';

// Your JSON data
const data = { "name": "Alice", "age": 30 };

// Convert to TOON format
const toonString = encode(data);
console.log(toonString);
// Output:
// name: Alice
// age: 30

// Convert back to JSON
const jsonData = decode(toonString);

No code needed to try it: paste data into the JSON to TOON converter, compare token counts in the TOON token calculator, or read the TOON format guide.