Compress JSON into Token-Oriented Object Notation (TOON) to reduce LLM token usage by up to 50%.
Token-Oriented Object Notation (TOON) is a compact format for representing arrays of objects. Instead of repeating keys for every object, TOON uses a tabular syntax:
[
{"name": "Alice", "age": 30, "city": "NYC"},
{"name": "Bob", "age": 25, "city": "LA"},
{"name": "Charlie", "age": 35, "city": "SF"}
][name|age|city]
Alice|30|NYC
Bob|25|LA
Charlie|35|SF
Result: ~50% reduction in tokens for LLM prompts!
- Real-time Conversion: Instant JSON to TOON transformation
- Token Counting: Compare character and estimated token counts
- Savings Calculator: See exact reduction percentages
- Syntax Highlighting: Easy-to-read formatted output
- Copy to Clipboard: One-click copy for LLM use
- Error Handling: Helpful messages for invalid JSON
- Node.js 18+
- npm or yarn
# Clone the repository
git clone https://github.com/kartikeykumar09/toon-converter.git
cd toon-converter
# Install dependencies
npm install
# Start development server
npm run devOpen http://localhost:5174 in your browser.
npm run build| Component | Technology |
|---|---|
| Framework | React 18 + TypeScript |
| Build Tool | Vite 5 |
| Styling | Vanilla CSS (Cyan accent) |
| Icons | Lucide React |
src/
βββ App.tsx # Main editor component
βββ index.css # Styling
βββ main.tsx # Entry point
βββ utils/
βββ toon.ts # TOON conversion logic
-
Header Row: Column names in brackets, separated by
|[column1|column2|column3] -
Data Rows: Values separated by
|, one row per objectvalue1|value2|value3 -
Escaping: Use
\|for literal pipe characters -
Nested Objects: Converted to inline JSON
function toTOON(jsonArray: object[]): string {
if (!Array.isArray(jsonArray) || jsonArray.length === 0) {
return JSON.stringify(jsonArray);
}
const keys = Object.keys(jsonArray[0]);
const header = `[${keys.join('|')}]`;
const rows = jsonArray.map(obj =>
keys.map(k => formatValue(obj[k])).join('|')
);
return [header, ...rows].join('\n');
}Contributions are welcome! Here's how you can help:
- Enhanced Nested Support: Better handling of deeply nested objects
- Array Values: Compact representation for array fields
- Type Preservation: Maintain number/boolean types in output
- Reverse Conversion: TOON β JSON parser
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature - Make your changes
- Run
npm run buildto verify - Commit:
git commit -m "Add your feature" - Push:
git push origin feature/your-feature - Open a Pull Request
| Data Type | JSON Tokens | TOON Tokens | Savings |
|---|---|---|---|
| User list (10 rows) | ~200 | ~100 | 50% |
| Product catalog | ~500 | ~280 | 44% |
| Log entries | ~1000 | ~450 | 55% |
MIT License - feel free to use this in your own projects!
- Built by Kartikey Kumar
- Part of the Free Developer Tools suite
