d4242163b28111ea0f239a2af599f8d94991cf1f
Some checks failed
CI / test (push) Has been cancelled
Data Format Converter CLI Tool
A CLI tool that converts between JSON, YAML, TOML, and CSV formats with validation, syntax highlighting, and an interactive TUI mode.
Features
- Multi-format conversion (JSON, YAML, TOML, CSV)
- Syntax validation with detailed error reporting
- Syntax highlighting using Rich library
- Interactive TUI mode for data viewing and editing
- File watching for live conversions
- Stdin/stdout support for piping
Installation
pip install data-format-converter
Or from source:
git clone https://7000pct.gitea.bloupla.net/7000pctAUTO/data-format-converter.git
cd data-format-converter
pip install -e .
Quick Start
Convert a JSON file to YAML:
dfc convert input.json -to yaml -o output.yaml
Convert CSV to JSON:
dfc convert data.csv -to json -o data.json
Validate a file:
dfc validate config.yaml
Interactive mode:
dfc tui config.json
Watch file for changes:
dfc watch input.yaml -to json -o output/
Usage
Usage: dfc [OPTIONS] COMMAND [ARGS]...
Commands
- convert: Convert between data formats
- validate: Validate syntax of data files
- tui: Launch interactive TUI mode
- watch: Watch files for changes and auto-convert
- info: Show information about supported formats
Options
--help: Show help message--theme: Set syntax highlighting theme (default, monokai, github-dark, github-light, dracula, nord, one-dark)
Examples
Basic Conversion
# JSON to YAML
dfc convert config.json -to yaml -o config.yaml
# YAML to TOML
dfc convert settings.yaml -to toml -o settings.toml
# CSV to JSON
dfc convert data.csv -to json -o data.json
# JSON to CSV
dfc convert data.json -to csv -o data.csv
Piping
# Read from stdin, write to stdout
cat config.json | dfc convert -f json -to yaml
# Use - for stdin/stdout
dfc convert input.yaml -to json - < input.yaml
Validation
# Validate a single file
dfc validate config.json
# Validate with detailed output
dfc validate --verbose config.yaml
# Validate from stdin
dfc validate --stdin --format json < config.json
Interactive Mode
# Open file in interactive viewer
dfc tui config.json
# Open with custom theme
dfc tui config.json --theme monokai
File Watching
# Watch a single file
dfc watch input.json -to yaml -o output/
# Watch multiple files (glob pattern)
dfc watch "*.json" -to yaml -o output/
File Formats
| Format | Extension | Read | Write |
|---|---|---|---|
| JSON | .json | ✓ | ✓ |
| YAML | .yaml, .yml | ✓ | ✓ |
| TOML | .toml | ✓ | ✓ |
| CSV | .csv | ✓ | ✓ |
Interactive Mode Controls
- Arrow keys: Navigate
- edit : Edit a value
- add : Add a new key
- delete : Delete a key
- show: Show current data
- save: Save changes
- quit: Exit without saving
- help: Show help
Configuration
Create a config.toml file in your home directory or specify with --config:
[default]
output_dir = "./output"
theme = "github-dark"
[convert]
indent = 2
[validate]
strict = false
Development
# Install in development mode
pip install -e ".[dev]"
# Run tests
pytest tests/ -v
# Run linter
ruff check .
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests:
pytest tests/ -v - Submit a pull request
License
MIT License
Description
A CLI tool that converts between JSON, YAML, TOML, and CSV formats with validation, syntax highlighting, and interactive TUI mode.