Overview
The TOON CLI provides a command-line interface for converting between JSON and TOON formats. It supports file I/O, stdin/stdout workflows, auto-detection, token statistics, and comprehensive formatting options.Installation
No Installation (npx)
Run directly with npx:Global Installation
toon command:
Basic Usage
Auto-Detection
The CLI automatically detects the conversion direction based on file extensions:Explicit Mode
Force encoding or decoding mode:Output to stdout
Omit the-o flag to print to stdout:
Reading from stdin
Pipe data or use- for stdin:
Command Options
Flags and Parameters
Encoding Options
Delimiter
Choose delimiter for tabular arrays:Tab delimiters reduce token count by ~5-10% compared to commas. Use tabs for LLM input where token efficiency matters most.
Indentation
Key Folding
Collapse single-key wrapper chains:Decoding Options
Strict Mode
Validate array lengths and field counts:Path Expansion
Expand dotted keys to nested objects:Custom Indentation
Match the indentation used during encoding:Token Statistics
Show token count comparison:Pipeline Workflows
JSON → TOON → File
File → TOON → Another Command
Round-Trip Conversion
Batch Processing
Real-World Examples
API Response Optimization
Database Export
Log Processing
LLM Prompt Preparation
Common Patterns
Quick Format Check
Compare Token Counts
Validation
Data Transformation
Environment Integration
Shell Scripts
Makefiles
GitHub Actions
Error Handling
Invalid JSON Input
Invalid TOON Input
File Not Found
Invalid Options
CLI Source Reference
The CLI implementation is available at:- Main command: packages/cli/src/index.ts
- Conversion logic: packages/cli/src/conversion.ts
- Utilities: packages/cli/src/utils.ts
1
Choose input source
Specify file path, use stdin with
-, or pipe data directly.2
Configure format options
Set delimiter, indentation, key folding, and other options.
3
Specify output destination
Use
-o for file output or omit for stdout.4
Review token statistics
Add
--stats flag to see token savings.Best Practices
Use tabs for LLM input
Add
--delimiter "\t" for maximum token efficiency.Enable key folding
Use
--keyFolding safe for nested structures to reduce tokens further.Check token savings
Add
--stats to quantify token reduction.Validate round-trips
Test that encoding + decoding preserves data integrity.
Troubleshooting
Command Not Found
Permission Denied
Large Files Timeout
Next Steps
Encoding Guide
Learn programmatic encoding with the TypeScript SDK
Streaming
Process large files with streaming APIs
LLM Integration
Use TOON format effectively with Large Language Models
