Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

20 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

toonconv πŸ¦€

Rust Version License GitHub stars GitHub issues

toonconv is a 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

  • πŸ“¦ Multiple Input Methods: Direct strings, stdin, files, and recursive directories
  • πŸ“Š Token Optimization: Reduces token count by 35-54% compared to JSON

πŸ“¦ Installation

Using Cargo (Easiest)

cargo install toonconv

From Source

# Clone the repository
git clone https://github.com/lst97/toonconv.git
cd toonconv

# Build release version
cargo build --release

# Install globally (optional)
cargo install --path .

Prerequisites

🎯 Quick Start

Basic Usage

# Direct JSON string (NEW!)
toonconv '{"name": "Alice", "age": 30}'

# From file
toonconv input.json -o output.toon

# From stdin
echo '{"status": "ok"}' | toonconv --stdin

# Batch directory conversion
toonconv input_dir/ -o output_dir/

Example Output

# Input JSON
{"users": [{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}]}

# Output TOON
users[2]{id,name}: 1,Alice 2,Bob

πŸ“š 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
toonconv '{"name": "Alice", "age": 30}'

# Convert a JSON array
toonconv '[1, 2, 3, 4, 5]'

# Nested structures
toonconv '{"user": {"name": "Bob", "email": "bob@example.com"}}'

2. Standard Input (stdin) πŸ”„

Great for Unix pipelines and data workflows.

# From echo
echo '{"status": "ok"}' | toonconv --stdin

# From API response
curl -s https://api.example.com/data | toonconv --stdin

# Chain with jq
jq '.results[]' data.json | toonconv --stdin

3. Single File Conversion πŸ“„

Convert individual files with custom output paths.

# Basic conversion
toonconv input.json

# Custom output
toonconv input.json -o custom_output.toon

# Pretty formatting
toonconv input.json --format pretty

4. Directory Batch Conversion πŸ“

Process entire directories while preserving structure.

# Recursive conversion (default)
toonconv input_dir/ -o output_dir/

# Non-recursive
toonconv input_dir/ -o output_dir/ --no-recursive

# Continue on errors
toonconv input_dir/ -o output_dir/ --continue-on-error

βš™οΈ Advanced Options

Format Control

# Pretty-print output (default)
toonconv data.json --format pretty

# Compact output
toonconv data.json --format compact

# Minified output
toonconv data.json --format minified

Memory Management

# Set memory limit (default: 512MB)
toonconv large.json --memory-limit 1073741824  # 1GB

# For very large files
toonconv huge.json --memory-limit 2147483648   # 2GB

Verbosity

# Quiet mode (errors only)
toonconv data.json --quiet

# Verbose mode (detailed progress)
toonconv data.json --verbose

# Debug mode (maximum detail)
toonconv data.json --debug

πŸ—οΈ 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: clap with derive macros
  • Performance: Optional simd-json support
  • Terminal UI: indicatif, console
  • File Operations: walkdir for recursive traversal

πŸ§ͺ Testing

Run the comprehensive test suite:

# All tests
cargo test

# TOON specification compliance
cargo test --test toon_spec_compliance_test

# Performance benchmarks
cargo bench

# Code quality
cargo clippy
cargo fmt

πŸ”§ Development

Building

# Development build
cargo build

# Release build (optimized)
cargo build --release

# Check code quality
cargo clippy
cargo fmt --check

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Make your changes and add tests
  4. Run the test suite: cargo test
  5. Submit a pull request

See AGENTS.md for development guidelines.

πŸ“– Documentation

πŸ’‘ Common Patterns

API to TOON Pipeline

# Fetch, filter, convert
curl -s https://api.example.com/users | \
  jq '.data.users' | \
  toonconv --stdin -o users.toon

Batch Convert with Error Handling

# Convert all JSON files, skip errors
find . -name "*.json" -type f | while read file; do
  toonconv "$file" -o "${file%.json}.toon" --continue-on-error
done

πŸ†˜ Troubleshooting

Build Issues

# Clean build
cargo clean
cargo update
cargo build --release

Runtime Errors

  • Invalid JSON: Validate input with a JSON validator
  • Memory limits: Increase with --memory-limit flag
  • 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.


About

A simple rust implementation of TOON (Token-Oriented Object Notation) convertor πŸ¦€

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages