A data-driven token efficiency comparison tool for JSON, TOON, YAML, and XML serialization formats. Built to demonstrate that compact JSON delivers nearly identical token savings to exotic formats like TOON, while remaining a format LLMs are already trained to understand.
🎮 Try it live at toon.donkeywork.dev
This application debunks social media hype around proprietary serialization formats by providing real-time, visual token count comparisons across three major AI providers (OpenAI, Anthropic, Google). Test with your own data and see the truth: compact JSON is efficient, familiar, and sufficient.
- Multi-Provider Token Counting:
- OpenAI (o200k_base encoding via
gpt-tokenizer) - Anthropic (configurable model selection via backend API)
- Google (configurable model selection via backend API)
- OpenAI (o200k_base encoding via
- Five Format Comparison: JSON (pretty & compact), TOON, YAML, and XML
- Visual Tokenization: Color-coded token breakdown with interactive tooltips
- Interactive Bar Chart: Horizontal bar chart comparing all formats across providers, sorted by efficiency
- Fully Responsive:
- Desktop (>1200px): 4-column output layout
- Tablet (768px-1200px): 2x2 grid output layout
- Mobile (<768px): Vertical stack with proper scrolling
- Example Data: Quick-load Simple and Advanced JSON examples
- Dark/Light Theme: Toggle between Material Design Indigo dark and light themes (defaults to dark)
- Copy to Clipboard: Easy export of any format
- Skeleton Loaders: Visual feedback during API calls
# Install dependencies
npm install
# Run dev server
npm run dev
# Build for production
npm run build- Set up environment variables:
# Copy the example env file
cp .env.example .env
# Edit .env and add your API keys
# ANTHROPIC_API_KEY=your_actual_anthropic_key
# GOOGLE_API_KEY=your_actual_google_key- Build and run:
# Build and run with Docker Compose
docker compose up -d
# Access at http://localhost:8081Or pull from registry:
docker pull 192.168.0.140:8443/toon-token:latestNote: The backend API requires valid Anthropic and Google API keys to function. You can get:
- Anthropic API key at: https://console.anthropic.com/
- Google API key at: https://aistudio.google.com/app/apikey
- Framework: React 19 + TypeScript + Vite
- UI Library: PrimeReact (Material Design Indigo theme)
- Token Counting:
- Client-side:
gpt-tokenizer(o200k_base) - Backend API: Anthropic and Google tokenizers
- Client-side:
- Format Libraries:
@toon-format/toon- TOON encodingjs-yaml- YAML serializationjs2xmlparser- XML serialization
- Charts: Chart.js via PrimeReact
- Deployment: Docker (multi-stage build with nginx)
- Input: Enter or load JSON data
- Parse: Application validates and converts to all formats
- Tokenize: Each format is tokenized using GPT's o200k_base encoding
- Compare: View token counts, percentages, and visual breakdowns
- Analyze: See that compact JSON is nearly as efficient as TOON
The application is built with modular, reusable React components:
- Header: Logo, theme toggle, GitHub link, and About button
- JsonInputPanel: JSON input with example loaders and format button
- OutputPanel: Reusable panel for all output formats with token visualization
- TokenChart: Interactive horizontal bar chart with model selection
- AboutDialog: Project information modal
- TokenDisplay: Token visualization with color-coding
- Top Row: JSON Input (left) | Token Chart (right)
- Bottom Row: JSON Output | TOON Output | YAML Output | XML Output
- Color-coded token breakdown (12-color palette)
- Hover tooltips show token ID and text
- Different color palettes for light/dark mode (Material Design variants)
- Horizontal bar chart comparing all formats
- Model selection dropdowns for Anthropic and Google
- Formats sorted by efficiency (smallest to largest average tokens)
- Skeleton loaders during API calls
- Dark mode optimized with proper contrast
Three breakpoints for optimal viewing:
- Desktop (>1200px): 4-column output layout
- Tablet (768px-1200px): 2x2 grid output layout
- Mobile (<768px):
- Full vertical stack layout
- Single column for all outputs
- Scrollable content with proper overflow handling
- Minimum heights to prevent content squeezing
- Chart gets 450px minimum height
Multi-stage build:
- Builder Stage: Node 20 Alpine - installs deps and builds
- Production Stage: Nginx Alpine - serves static files
# Build
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
# Serve
FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
EXPOSE 80- Initial Data: Advanced glossary example
- Output Format: Compact JSON (demonstrates efficiency)
- Theme: Dark mode (md-dark-indigo)
- Tokenization View: Always enabled with color-coded display
- Port: 8081 (Docker Compose)
- Build Output:
dist/ - Assets:
src/assets/
src/
├── App.tsx # Main application logic and state
├── App.css # Responsive styles (mobile/tablet/desktop)
├── index.css # Global styles, PrimeReact imports
├── main.tsx # Entry point
├── api/
│ ├── index.ts # API exports
│ ├── client.ts # Backend API calls
│ └── types.ts # TypeScript interfaces
├── components/
│ ├── Header.tsx # App header with actions
│ ├── JsonInputPanel.tsx # JSON input editor
│ ├── OutputPanel.tsx # Reusable output display
│ ├── TokenChart.tsx # Chart with model selection
│ ├── AboutDialog.tsx # About modal
│ └── TokenDisplay.tsx # Token visualization
└── assets/
├── donkeywork.png # Logo
└── favicon.ico # Favicon
public/ # Static assets
index.html # HTML entry with dynamic theme link
Dockerfile # Multi-stage build
docker-compose.yml # Docker Compose configuration
CLAUDE.md # Detailed project documentation
This project demonstrates a specific thesis: compact JSON is efficient. Contributions that enhance the comparison or improve the user experience are welcome.
MIT
Andrew Morgan AI Engineer at Airia
- LinkedIn: andrewjmorgan
- GitHub: andyjmorgan
Built with:
- PrimeReact - UI component library
- @toon-format/toon - TOON encoding
- gpt-tokenizer - Token counting
- js-yaml - YAML serialization
Real talk: If social media "experts" are hyping exotic formats while ignoring the simplicity of JSON compact, they're talking out their ass. Test it yourself—the data doesn't lie.
