A simple JSON ↔ YAML converter CLI tool
Project description
yamljson
A lightweight command-line tool to convert files between JSON and YAML formats.
Table of Contents
- Overview
- Features
- Requirements
- Installation
- Usage
- Programmatic API
- Project Tree
- How It Works
- Error Cases and Notes
- Development
Overview
yamljson is built for fast, simple, local file conversion:
- Convert
.jsonfiles to.yaml - Convert
.yamlfiles to.json - Use a single command with a predictable output filename
This project is ideal for quick data format switching in scripts, dev tooling, and config workflows.
Features
- Simple CLI command:
convert - Bidirectional conversion: JSON to YAML, YAML to JSON
- UTF-8 file handling
- Human-readable JSON output (
indent=4) - Safe YAML operations (
yaml.safe_load,yaml.safe_dump)
Requirements
- Python
>=3.8 PyYAML
Installation
1. Clone the repository
git clone <your-repository-url>
cd yamljson
2. Install locally
pip install .
This registers the CLI script:
convert
Usage
CLI syntax
convert <filename> --to yaml
convert <filename> --to json
Examples
JSON to YAML
convert data.json --to yaml
Output file:
data.yaml
YAML to JSON
convert config.yaml --to json
Output file:
config.json
Common CLI responses
File not found: <filename>if the input file does not existInvalid option. Use: --to yaml | jsonif--tois missingUnknown target format. Use 'yaml' or 'json'.for unsupported targetsConversion failed: <reason>for parsing and file I/O errors
Programmatic API
You can also use the converter functions directly in Python:
from yamljson.converter import ConversionError, json_to_yaml, yaml_to_json
try:
json_to_yaml("data.json", "data.yaml")
yaml_to_json("config.yaml", "config.json")
except ConversionError as exc:
print(f"Conversion failed: {exc}")
Project Tree
yamljson/
├── LICENSE
├── README.md
├── pyproject.toml
├── tests/
│ ├── test_cli.py
│ └── test_converter.py
└── yamljson/
├── __init__.py
├── cli.py
└── converter.py
How It Works
yamljson/cli.pyparses CLI arguments.- It validates the file path and conversion target.
- It routes the operation to:
json_to_yaml(...)oryaml_to_json(...)
yamljson/converter.pyreads input and writes converted output.
Error Cases and Notes
- Invalid JSON input raises
ConversionError. - Invalid YAML input raises
ConversionError. - YAML values not representable in JSON raise
ConversionError. - Output files are created in the same directory as the input file.
- Output filename is generated from the input basename:
name.json->name.yamlname.yaml->name.json
Development
Install editable mode for local development:
pip install -e .
Run tests (if/when tests are added/expanded):
python -m pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yamljson-1.0.0.tar.gz.
File metadata
- Download URL: yamljson-1.0.0.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
981b39c357c414f6fdf962324de9ffe0d0d5580cc5d3f46c09bf5b3f25565bdd
|
|
| MD5 |
bc5a6dc1a576395614456023e8a5146b
|
|
| BLAKE2b-256 |
a5d399832b1a48b094140e15f2dacd92330ff5068299e250bf01bc70bd091787
|
File details
Details for the file yamljson-1.0.0-py3-none-any.whl.
File metadata
- Download URL: yamljson-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e23a1178bd9b4faa680272ed6d51b173e3b3185c7428c93184588d42dfaf2d7f
|
|
| MD5 |
40917895b20aa8144ca43ab0d0f07770
|
|
| BLAKE2b-256 |
83824a7bc408cd967d4183ed5b4958ec609f95a9844015b7c62b020583e8e757
|