What is yq
Last updated: April 2, 2026
Key Facts
- yq was first released on GitHub in 2015 and has accumulated over 11,000 GitHub stars as of 2024
- Written in Go, yq is deployed as a single dependency-free binary for Windows, macOS, and Linux systems
- yq supports 6 primary file formats: YAML, JSON, XML, CSV, TOML, and HCL with identical query syntax across all formats
- The tool uses jq-compatible filtering syntax, allowing developers familiar with jq to adopt yq with minimal learning curve
- yq processes deeply nested configuration files with support for array slicing, conditional logic, and multi-file merging in single commands
Overview
yq is a command-line YAML query processor that brings the power of jq (the popular JSON command-line tool) to YAML and multiple other data formats. Released in 2015 by Mike Farah on GitHub, yq has evolved into an indispensable utility for DevOps engineers, Kubernetes administrators, and software developers who work with configuration files. The tool is written in Go, which means it compiles into a single, dependency-free binary executable available for Windows, macOS, and Linux. This portability makes it trivial to integrate yq into CI/CD pipelines, Docker containers, and automation scripts without requiring additional dependencies or language runtimes.
At its core, yq is designed to solve a critical problem in modern DevOps: the need to programmatically read, parse, modify, and validate YAML configuration files from the command line. While tools like sed and awk can manipulate text, they understand only strings and regular expressions. yq understands the actual structure and meaning of YAML documents, enabling powerful data transformations impossible with traditional text processors. Its syntax is based on jq, the de facto standard for JSON command-line processing, making it familiar to anyone already using jq in their workflows.
Core Capabilities and Technical Features
yq supports six primary data formats out of the box: YAML, JSON, XML, CSV, TOML, and HCL (HashiCorp Configuration Language). This multi-format support is crucial for modern infrastructure, where configurations are distributed across different file formats. For example, a DevOps engineer might use yq to extract values from a YAML Kubernetes manifest, transform a JSON API response, parse an INI configuration file, and export results in any supported format—all without switching tools.
The query language itself is exceptionally powerful. Users can traverse deeply nested data structures using dot notation (e.g., .metadata.name to access nested YAML keys), filter arrays based on conditions, perform string transformations, merge multiple files intelligently, and apply conditional logic within single commands. A typical use case: extracting all container image names from a Kubernetes deployment manifest across dozens of pod specifications. In traditional shell scripting, this would require complex pipes combining grep, sed, and awk. With yq, it's a single line: yq '.spec.template.spec.containers[].image' deployment.yaml.
yq includes advanced features like recursive descent (finding all values matching a pattern regardless of nesting depth), custom functions, string interpolation, and environment variable substitution. The tool can read from files, stdin, or URLs, and output results in any supported format. This flexibility enables seamless integration into shell scripts, Makefiles, Terraform workflows, and CI/CD pipelines like GitHub Actions, GitLab CI, and Jenkins.
Why yq Became Essential in DevOps
The explosion of YAML-based infrastructure tools created demand for yq. Kubernetes, the de facto standard for container orchestration, uses YAML exclusively for manifests defining deployments, services, and configurations. Ansible, Helm, Docker Compose, and numerous other modern tools also rely on YAML. By 2020, yq had become the standard tool for automating YAML manipulation in these ecosystems. Companies including Kubernetes distributions, major cloud providers, and enterprise DevOps teams now include yq in their standard toolsets.
Real-world examples demonstrate yq's utility: A platform engineering team uses yq in CI/CD to validate that all container images come from approved registries before deployment. An infrastructure team uses yq to automatically update image tags in hundreds of Kubernetes manifests during releases. A configuration management system uses yq to transform legacy XML configs into modern YAML format. A monitoring system uses yq to extract metric labels from application configurations and generate alert rules dynamically.
Common Misconceptions About yq
Misconception 1: yq is only for Kubernetes. While yq gained popularity in the Kubernetes ecosystem, it's a general-purpose YAML processor useful for any application using YAML, JSON, XML, or other supported formats. Many teams use yq for Ansible playbooks, Docker Compose files, Helm value files, Terraform configuration, and generic application config files unrelated to Kubernetes.
Misconception 2: yq requires learning a complex new language. yq uses jq's syntax, which while powerful, is fundamentally a filter-based approach similar to Unix pipes. Beginners can accomplish 80% of practical tasks with basic filters (selecting fields, filtering arrays, simple transformations). Advanced features are available for complex scenarios, but most daily use cases involve straightforward queries.
Misconception 3: yq is slow or unsuitable for large files. yq performs well even with large YAML documents. Its Go implementation is efficient, and it streams data intelligently. Real-world tests show yq processes multi-megabyte configuration files in milliseconds, making it suitable for production CI/CD environments where performance matters.
Practical Integration and Workflow Examples
In practice, yq integrates into workflows through simple command invocations. A Dockerfile might use yq to extract configuration at build time. A Bash script might use yq to validate that critical configuration values are present before deploying. A GitHub Actions workflow might use yq to update image tags in manifest files automatically. A Terraform automation might use yq to transform external YAML sources into Terraform-compatible format.
Installation is straightforward: download the appropriate binary for your OS, make it executable, and it's ready to use. Many package managers (Homebrew, apt, yum) provide yq packages. Docker users can invoke yq without local installation using official Docker images. This low barrier to adoption explains yq's widespread adoption across diverse teams and environments.
For teams heavily invested in configuration-as-code practices, yq becomes as essential as git or Docker. It enables automation that would otherwise require custom scripts in Python, Ruby, or other languages, reducing development effort and improving consistency. The tool's single-binary model also simplifies distribution and deployment across air-gapped or restricted environments where language runtimes might be unavailable.
Related Questions
How is yq different from jq?
yq is specifically designed for YAML files while jq handles JSON exclusively. yq uses jq-compatible syntax but adds YAML-specific features like comment preservation and anchor handling. Both tools process data structurally rather than as plain text, but yq extends beyond jq's single-format approach to support YAML, XML, CSV, TOML, and HCL simultaneously, making it more versatile for modern infrastructure tools that mix multiple configuration formats.
Can yq modify files in place?
Yes, yq supports in-place file modification using the -i or --inplace flag. For example, 'yq -i '.spec.replicas = 3' deployment.yaml' modifies the file directly. This capability is crucial for automation scripts that update configuration files during CI/CD pipelines or infrastructure provisioning workflows without requiring intermediate temporary files or complex redirection logic.
Is yq suitable for production CI/CD pipelines?
Absolutely. yq is widely used in production CI/CD environments by major companies and open-source projects. Its performance handles large files efficiently, its single-binary deployment eliminates dependency issues, and its deterministic behavior makes it reliable for automation. Many cloud providers and Kubernetes distributions include yq in their standard tooling recommendations.
What are common yq use cases in DevOps?
Common use cases include: validating Kubernetes manifests before deployment, extracting and updating image tags during releases, transforming configuration formats, merging multiple YAML files in build processes, extracting specific values for logging or monitoring, and automating configuration updates across infrastructure. yq's versatility makes it applicable wherever structured configuration manipulation is needed.
Does yq handle comments in YAML files?
Yes, yq preserves YAML comments by default when processing and modifying files. This is a significant advantage over simpler text processors that strip comments during transformations. Preserving comments is essential in configuration management where comments document intent and decisions, preventing loss of critical context during automated updates.