LinuxCommandLibrary

yq

TLDR

Read a value from a YAML file

$ yq '.[key]' [file.yaml]
copy
Read a nested value
$ yq '.[parent].[child]' [file.yaml]
copy
Convert YAML to JSON
$ yq -o=json [file.yaml]
copy
Convert JSON to YAML
$ yq -p=json [file.json]
copy
Edit a file in place
$ yq -i '.[key] = "value"' [file.yaml]
copy
Merge multiple YAML files
$ yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' [file1.yaml] [file2.yaml]
copy
Select items from an array
$ yq '.items[] | select(.name == "foo")' [file.yaml]
copy
Count array elements
$ yq '.items | length' [file.yaml]
copy

SYNOPSIS

yq [options] expression [file ...]

DESCRIPTION

yq is a lightweight command-line YAML, JSON, XML, CSV, TOML, and properties processor. It uses jq-like syntax for querying and manipulating structured data, making it easy to extract values, modify documents, and convert between formats.
The tool supports reading from files or stdin, and can output to stdout or edit files in place. Expressions follow a path-based syntax similar to jq, allowing complex queries and transformations.
Two implementations exist: mikefarah/yq (Go-based, standalone binary) and kislyuk/yq (Python wrapper around jq). The Go version is more commonly installed via package managers.

PARAMETERS

-i, --inplace

Edit files in place.
-p, --input-format format
Input format: yaml, json, xml, props, csv, tsv, toml.
-o, --output-format format
Output format: yaml, json, xml, props, csv, tsv.
-I, --indent n
Set indentation level (default 2).
-C, --colors
Force colored output.
-M, --no-colors
Disable colored output.
-N, --no-doc
Don't print document separators.
-e, --exit-status
Set exit status based on expression result.
--from-file file
Load expression from a file.
-n, --null-input
Don't read input; useful for creating new documents.
-s, --split-exp expression
Split output into multiple files.
-v, --verbose
Enable verbose output.
-h, --help
Display help message.
-V, --version
Display version information.

CAVEATS

The two yq implementations have different syntax and capabilities. The Go version (mikefarah/yq) uses its own expression language, while the Python version (kislyuk/yq) uses jq syntax directly. Check which version is installed with yq --version.

HISTORY

The Python yq wrapper was created by Andrey Kislyuk and released in 2017 as a thin jq wrapper for YAML. The Go-based yq was created by Mike Farah around the same time as a standalone tool. The Go version has become more popular due to being a single binary with no dependencies and supporting multiple formats beyond YAML.

SEE ALSO

jq(1), xmlstarlet(1), dasel(1), fx(1)

> TERMINAL_GEAR

Curated for the Linux community

BOSGAME Mini PC N95, Intel 12th Mini Computers| 16GB DDR4 RAM| 512GB M.2 2280 SSD| 4K 60HZ Triple Displays by Dual HDMI+Type-C, 6W TDP Quiet Mini PC, WIFI5, BT 5.0 Office

BOSGAME Mini PC N95, Intel 12th Mini Computers| 16GB DDR4 RAM| 512GB M.2 2280 SSD| 4K 60HZ Triple Displays by Dual HDMI+Type-C, 6W TDP Quiet Mini PC, WIFI5, BT 5.0 Office

$239.99
Bmax Mini PC B2 Power Intel 5205U 8GB DDR4 256GB M.2 NVMe SSD ,HDMI 1.4&DP 1.2, USB3.2,4K Dual Display 2.4G/5G WiFi & BT5.0 Mini Desktop Computers /Office/Design

Bmax Mini PC B2 Power Intel 5205U 8GB DDR4 256GB M.2 NVMe SSD ,HDMI 1.4&DP 1.2, USB3.2,4K Dual Display 2.4G/5G WiFi & BT5.0 Mini Desktop Computers /Office/Design

$169.99
Lenovo Gen 13 ThinkPad X1 Carbon Touchscreen Laptop with Intel Ultra 7 265U Processor, 14" WUXGA 100% sRGB, 32GB DDR5 RAM, 1TB NVMe Performance SSD, FHD+ IR+ RGB Camera, and Windows 11 Pro

Lenovo Gen 13 ThinkPad X1 Carbon Touchscreen Laptop with Intel Ultra 7 265U Processor, 14" WUXGA 100% sRGB, 32GB DDR5 RAM, 1TB NVMe Performance SSD, FHD+ IR+ RGB Camera, and Windows 11 Pro

$1,589.00
Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community

KIWITATA 2X Classic SNES USB Controller for PC Gamings, Retro SNES Wired USB Game Emulator Controller for Windows XP 7 8 11 Mac Raspberry Pi

KIWITATA 2X Classic SNES USB Controller for PC Gamings, Retro SNES Wired USB Game Emulator Controller for Windows XP 7 8 11 Mac Raspberry Pi

$16.99
BOSGAME Mini PC N95, Intel 12th Mini Computers| 16GB DDR4 RAM| 512GB M.2 2280 SSD| 4K 60HZ Triple Displays by Dual HDMI+Type-C, 6W TDP Quiet Mini PC, WIFI5, BT 5.0 Office

BOSGAME Mini PC N95, Intel 12th Mini Computers| 16GB DDR4 RAM| 512GB M.2 2280 SSD| 4K 60HZ Triple Displays by Dual HDMI+Type-C, 6W TDP Quiet Mini PC, WIFI5, BT 5.0 Office

$239.99
New Raspberry Pi 3 Model B+ Board Raspberry PI 3B+

New Raspberry Pi 3 Model B+ Board Raspberry PI 3B+

$54.00