# yq

> Command-line YAML, JSON, XML, and CSV processor with jq-like syntax for querying and transforming structured data

Stars: 16.2k · Language: Go · License: MIT · Categories: Data

- Repository: https://github.com/mikefarah/yq
- Website: https://mikefarah.gitbook.io/yq/
- Page: https://www.trmn.sh/tools/yq
- Demo video: https://media.trmn.sh/demos/c81ffd42a494a2832b2e4f0bbab39e1d18aa6fbfac5dfd71ae2c0cec4dbed006.mp4

## Install

- Homebrew: `brew install yq`
- Snap: `snap install yq`
- Go Install: `go install github.com/mikefarah/yq/v4@latest`

## Overview

yq is a command-line processor for YAML, JSON, XML, CSV, INI, and other structured data formats. It uses jq-like syntax for querying and transforming data, allowing operations like reading values (`.a.b[0].c`), updating files in-place with `-i`, and merging multiple documents. The tool supports format conversion between YAML, JSON, XML, CSV, and other formats using output flags like `-o json`.

Built as a dependency-free Go binary, yq handles multi-document YAML files, preserves formatting and comments during updates, and supports advanced operations like array filtering, conditional updates, and environment variable substitution. It can merge files using `load()` functions, perform reductions across datasets, and manipulate YAML-specific features like anchors, aliases, and front matter blocks.

The tool integrates with Docker/Podman containers, GitHub Actions, and various package managers. It includes shell completion for bash/zsh/fish/PowerShell and supports piped input/output workflows. yq is particularly useful for DevOps engineers, developers working with configuration files, and CI/CD pipelines that need to manipulate structured data programmatically.

### Installation

```bash
# via Homebrew
brew install yq
```

```bash
# via Snap
snap install yq
```

```bash
# via Go Install
go install github.com/mikefarah/yq/v4@latest
```

## Alternatives

- [gron](https://www.trmn.sh/tools/gron.md): Transforms JSON into discrete assignments to make it greppable and enable exploration of complex JSON structures (Go, 14.5k stars)
- [fx](https://www.trmn.sh/tools/fx.md): Terminal-based JSON processor and viewer for querying, filtering, and manipulating JSON data interactively. (Go, 20.7k stars)
- [usql](https://www.trmn.sh/tools/usql.md): Universal command-line SQL client with PostgreSQL psql-inspired interface for multiple databases (Go, 10.2k stars)
- [miller](https://www.trmn.sh/tools/miller.md): Command-line data processing tool for CSV, TSV, JSON, and JSON Lines with field-based operations (Go, 10.1k stars)
- [pup](https://www.trmn.sh/tools/pup.md): Command line HTML processing tool using CSS selectors to filter and extract data from HTML documents (Go, 8.4k stars)

## Guides

- [Change YAML configuration with yq](https://www.trmn.sh/guides/yq-edit-yaml-safely): Read and update a nested YAML value with mikefarah/yq, preview the result, then write it to a disposable file.
- [Best JSON CLI Tools](https://www.trmn.sh/best/json-cli-tools): Compare jq, yq, gojq, fx, dasel, gron and qo for querying, filtering and transforming JSON (and YAML) from the command line.

---

Canonical: https://www.trmn.sh/tools/yq
