Skip to main content

A simple JSON ↔ YAML converter CLI tool

Project description

yamljson

Python Version CLI Dependency Format

A lightweight command-line tool to convert files between JSON and YAML formats.

Table of Contents

Overview

yamljson is built for fast, simple, local file conversion:

  • Convert .json files to .yaml
  • Convert .yaml files 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 exist
  • Invalid option. Use: --to yaml | json if --to is missing
  • Unknown target format. Use 'yaml' or 'json'. for unsupported targets
  • Conversion 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

  1. yamljson/cli.py parses CLI arguments.
  2. It validates the file path and conversion target.
  3. It routes the operation to:
    • json_to_yaml(...) or
    • yaml_to_json(...)
  4. yamljson/converter.py reads 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.yaml
    • name.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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yamljson-1.0.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yamljson-1.0.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

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

Hashes for yamljson-1.0.0.tar.gz
Algorithm Hash digest
SHA256 981b39c357c414f6fdf962324de9ffe0d0d5580cc5d3f46c09bf5b3f25565bdd
MD5 bc5a6dc1a576395614456023e8a5146b
BLAKE2b-256 a5d399832b1a48b094140e15f2dacd92330ff5068299e250bf01bc70bd091787

See more details on using hashes here.

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

Hashes for yamljson-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e23a1178bd9b4faa680272ed6d51b173e3b3185c7428c93184588d42dfaf2d7f
MD5 40917895b20aa8144ca43ab0d0f07770
BLAKE2b-256 83824a7bc408cd967d4183ed5b4958ec609f95a9844015b7c62b020583e8e757

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page