# jsonyaml-cli
Lightweight, no-nonsense CLI to convert **JSON ⇄ YAML**.
## Features
- Auto-detects input format (by extension or content).
- Converts JSON ⇄ YAML with sane defaults.
- Supports:
- Multi-document YAML
- JSON Lines / NDJSON
- Strict mode for duplicate YAML keys
- UTF-8 safe with PowerShell notes below.
## Install
Editable install for local dev:
```powershell
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -e ".[test]"Check version:
jsonyaml --versionjsonyaml -i .\data.json -o .\data.yamljsonyaml -i .\data.yaml -o .\data.jsonjsonyaml -i .\multi.yml --from yaml --to json --multi array -o .\multi.jsonjsonyaml -i .\logs.ndjson --from json --json-lines --to yaml -o .\logs.yaml'{"hello":"world","nums":[1,2,3]}' | jsonyaml --from json --to yamlI/O
-i, --in, --input PATH Input path (default: stdin, use "-")
-o, --out, --output PATH Output path (default: stdout)
Direction
--from {json,yaml} Override input format
--to {json,yaml} Desired output format
YAML
--yaml-indent INT Indent (default: 2)
--yaml-flow Use flow style
--yaml-sort-keys Sort keys
--yaml-doc-start Prefix docs with '---'
--yaml-strict-dupes Error on duplicate keys during YAML load
JSON
--json-indent INT Indent (default: 2)
--json-sort-keys Sort keys
--json-ensure-ascii Escape non-ASCII (default: UTF-8)
--json-lines Treat input as JSON Lines / NDJSON
--multi {array,lines,first} YAML→JSON multi-doc strategy (default: array)
General
--strict Nonzero exit on empty input, etc.
-q, --quiet Suppress diagnostics
--version Show version
-
PS 5.x writes UTF-8 files with a BOM by default, which can cause
Unexpected UTF-8 BOMparse errors. Fixes:-
Use PS 7+ with
-Encoding utf8NoBOM, or -
Re-save without BOM:
$txt = Get-Content .\data.json -Raw -Encoding UTF8 [IO.File]::WriteAllText(".\data.json", $txt, (New-Object System.Text.UTF8Encoding($false)))
-
Or pipe instead of using
-i/-o:Get-Content .\data.json -Raw -Encoding UTF8 | jsonyaml --from json --to yaml
-
-
Always quote paths with spaces, e.g.:
jsonyaml -i "C:\Users\Wilson\Documents\my data\input.json" -o .\out.yaml
Run the test suite:
pytest -qMIT