toonconv ๐ฆ
toonconv is a blazingly fast, high-performance Rust CLI tool for converting JSON data into TOON (Token-Oriented Object Notation) format. It's designed for LLM applications, data processing pipelines, and scenarios where token efficiency matters.
โจ Key Features
- ๐ Ultra-Fast Performance: ~190x faster than JavaScript implementations
- ๐พ Memory Efficient: Optional SIMD acceleration and configurable memory limits
- ๐ฆ Multiple Input Methods: Direct strings, stdin, files, and recursive directories
- ๐ Batch Processing: Process entire directory structures automatically
- ๐ Token Optimization: Reduces token count by 35-54% compared to JSON
- ๐ก๏ธ Robust Error Handling: Continues processing on errors with detailed reporting
- ๐ Built-in Performance Monitoring: Real-time progress bars and statistics
๐ Performance Benchmarks
| Implementation | CLI Execution Time | Token Efficiency |
|---|---|---|
| toonconv (Rust) | ~5ms | 35-54% reduction |
| @toon-format/cli (JS) | ~959ms | Baseline |
Benchmarks run on Apple M1 Mac Air. See BENCHMARK.md for detailed analysis.
๐ฆ Installation
From Source (Recommended)
# Clone the repository
# Build release version
# Install globally (optional)
Prerequisites
- Rust 1.75+ (Install Rust)
๐ฏ Quick Start
Basic Usage
# Direct JSON string (NEW!)
# From file
# From stdin
|
# Batch directory conversion
Example Output
# Input JSON
}
# Output TOON
}
๐ Usage Methods
toonconv supports 4 different ways to convert JSON to TOON:
1. Direct JSON String Argument ๐ฏ
Perfect for quick conversions and testing.
# Convert a JSON object
# Convert a JSON array
# Nested structures
2. Standard Input (stdin) ๐
Great for Unix pipelines and data workflows.
# From echo
|
# From API response
|
# Chain with jq
|
3. Single File Conversion ๐
Convert individual files with custom output paths.
# Basic conversion
# Custom output
# Pretty formatting
4. Directory Batch Conversion ๐
Process entire directories while preserving structure.
# Recursive conversion (default)
# Non-recursive
# Continue on errors
โ๏ธ Advanced Options
Format Control
# Pretty-print output (default)
# Compact output
# Minified output
Memory Management
# Set memory limit (default: 512MB)
# For very large files
Verbosity
# Quiet mode (errors only)
# Verbose mode (detailed progress)
# Debug mode (maximum detail)
๐๏ธ Architecture
toonconv/
โโโ src/
โ โโโ cli/ # CLI argument parsing and commands
โ โโโ conversion/ # Core conversion engine
โ โโโ formatter/ # TOON format output generation
โ โโโ parser/ # JSON parsing with validation
โ โโโ validation/ # Input validation and error handling
โ โโโ error/ # Custom error types
โ โโโ lib.rs # Library entry point
โ โโโ main.rs # Binary entry point
โโโ tests/ # Comprehensive test suite
โโโ benches/ # Performance benchmarks
โโโ examples/ # Usage examples
โโโ specs/ # TOON format specifications
Core Technologies
- Language: Rust 1.75+
- JSON Processing:
serde,serde_json - CLI Framework:
clapwith derive macros - Performance: Optional
simd-jsonsupport - Terminal UI:
indicatif,console - File Operations:
walkdirfor recursive traversal
๐งช Testing
Run the comprehensive test suite:
# All tests
# TOON specification compliance
# Performance benchmarks
# Code quality
๐ Benchmarking
Compare performance with the official JavaScript implementation:
# Run built-in benchmarks
# Compare with JavaScript version
See BENCHMARK.md for detailed performance analysis.
๐ง Development
Building
# Development build
# Release build (optimized)
# Check code quality
Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes and add tests
- Run the test suite:
cargo test - Submit a pull request
See AGENTS.md for development guidelines.
๐ Documentation
- USAGE_GUIDE.md: Comprehensive usage examples and patterns
- BUILD.md: Build instructions and troubleshooting
- BENCHMARK.md: Performance analysis and comparisons
- specs/: TOON format specifications
๐ก Common Patterns
API to TOON Pipeline
# Fetch, filter, convert
| \
| \
Batch Convert with Error Handling
# Convert all JSON files, skip errors
| while ; do
done
Git Hook Integration
#!/bin/bash
# .git/hooks/pre-commit
for; do
done
๐ Troubleshooting
Build Issues
# Clean build
Runtime Errors
- Invalid JSON: Validate input with a JSON validator
- Memory limits: Increase with
--memory-limitflag - File not found: Use absolute paths if relative paths fail
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- TOON format specification contributors
- Rust ecosystem for excellent tooling
- Performance benchmarking frameworks
Website โข Documentation โข Issues โข Discussions
Made with โค๏ธ using Rust