Skip to content
Latchkey

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

Terminal
# 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

FlagWhat it does
-yjYAML to JSON (this is the default)
-jyJSON to YAML
-tj / -jtTOML to JSON / JSON to TOML
-hjHCL to JSON
-yy / -jjReformat within the same format
-iPretty-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.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →