yq is a lightweight, portable command-line YAML processor. Similar to jq but for YAML, it enables querying and manipulating YAML files with a simple expression syntax.
📑 Table of Contents
Key Features
- YAML Support: Read, write, and transform YAML
- JSON Conversion: Convert between formats
- jq-like Syntax: Familiar expression language
- In-Place Edit: Modify files directly
- Multi-Document: Handle YAML streams
Installation
Install yq:
# Via snap
sudo snap install yq
# Via wget
wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/local/bin/yq
chmod +x /usr/local/bin/yq
Usage Examples
Common yq operations:
# Read value
yq ".apiVersion" deployment.yaml
# Update value
yq -i ".spec.replicas = 5" deployment.yaml
# Add item to array
yq -i ".items += [\"new\"]" config.yaml
# Convert YAML to JSON
yq -o json config.yaml
Benefits
yq brings jq-style power to YAML files. Essential for managing Kubernetes manifests and configuration files from the command line.
Was this article helpful?