yj: Convert Between YAML, TOML, JSON and HCL
yj converts a document between YAML, TOML, JSON and HCL, choosing direction with a two-letter flag like -yj (YAML to JSON).
When one tool speaks JSON and your config is YAML or TOML, yj bridges them in a single pipe. The flag names the source and target formats.
What it does
yj reads from stdin and writes to stdout, converting between formats. The flag encodes from/to: the first letter is the input (y, t, j, h, c for YAML/TOML/JSON/HCL/CSON-style) and the second is the output. Default with no flag is YAML to JSON.
Common usage
# YAML -> JSON (the default)
yj < config.yaml
# TOML -> JSON
yj -tj < Cargo.toml
# JSON -> YAML
yj -jy < data.json
# YAML -> JSON, then query with jq
yj < deploy.yaml | jq '.spec.replicas'Options
| Flag | What it does |
|---|---|
| -yj | YAML to JSON (this is the default) |
| -jy | JSON to YAML |
| -tj / -jt | TOML to JSON / JSON to TOML |
| -hj | HCL to JSON |
| -yy / -jj | Reformat within the same format |
| -i | Pretty-print/indent the JSON output |
In CI
Let jq operate on YAML by converting first: yj < values.yaml | jq -r ".image.tag". This avoids adding a separate YAML query tool when your pipeline already standardizes on jq, and it round-trips back with -jy if a step needs YAML out.
Common errors in CI
yj: command not found: install with go install github.com/sclevine/yj/v5@latest or a release binary. A YAML duplicate key fails conversion because JSON objects cannot hold duplicate keys. YAML that relies on anchors/merge keys may not survive cleanly through JSON. Note there are similarly named tools (yj by sclevine vs others); flag syntax differs, so confirm which yj the image ships.