yq Interactive Docs
yq on GitHub
Interactive Tutorial

Mastering YAML Querying & Editing

A step-by-step developer guide. Each command has a live terminal workspace sandbox. Click pause on any screen to type, query, or edit the files yourself.

Step 01

Querying Nested Fields

To read values from a YAML file, specify their paths using dot notation. Nested attributes map directly to their parent key scopes.

config.yaml
app:
  name: "Deploy Service"
  version: "2.1.0"
  settings:
    port: 8080
Command
./yq '.app.name' config.yaml
Step 02

In-Place Modifications

You can append elements to arrays using the += operator. Add the -i flag to commit these changes directly to the file itself.

config.yaml
app:
  settings:
    tags:
      - production
      - web
Command
./yq -i '.app.settings.tags += ["api"]' config.yaml
Step 03

Converting YAML to JSON

To integrate YAML configurations into tools that require JSON payloads, use the -o=json flag to format the parsed document as JSON.

config.yaml
app:
  name: "Deploy Service"
  version: "2.1.0"
Command
./yq -o=json config.yaml