YAML Is Structured Data — Search and Edit It With a Dedicated Tool

date 2026-06-27 read 3 min tags #yaml #cli #tools

In my last article about languages in YAML costumes, I complained that Helm templatized YAML with a text templating engine. YAML is a language that serializes data structure into text. It would be better to manipulate the data structure that YAML represents as data instead of text.

Because a small part of my day job requires me to work on hieradata inventories, I frequently come across a huge number of YAML files I need to dig in. Often, I need to see if a key is defined for a specific environment, or which environments define a specific key. But because YAML uses indentation and new lines as syntax, most greps are imprecise:

$ grep enabled test.yaml
  enabled: true
    enabled: true
    enabled: false

Looking for the string "enabled" yields many results, and it's hard to know which are relevant. What is enabled and disabled here?

For small files, viewing the whole file might be enough to grasp the needed information:

---
app1:
  enabled: true
  feature:
    enabled: true
  port: 1234
app2:
  port: 8080
  ingress:
    enabled: false

But what if, like me, you manage hundreds of YAML files in nested file trees? Grep scales poorly for this specific use case.

ym: grep that understands key paths

A few weeks ago, I wrote a CLI utility called ym (YAML Manipulator) that tackles exactly this issue:

$ ym grep enabled test.yaml
app1.enabled: true
app1.feature.enabled: true
app2.ingress.enabled: false

The subcommand ym grep returns the whole path of all the keys that matched, including the value at that path.

As a disclaimer, yq can do this:

$ yq '.. | select(key == "enabled") | (path | join(".")) + ": " + (. | tostring)' test.yaml
app1.enabled: true
app1.feature.enabled: true
app2.ingress.enabled: false

The ergonomics are a bit rough, but it works.

ym has a few benefits added on top of this though:

  1. Like grep, it can target a directory and read YAML data from stdin.
  2. I added a few other subcommands: set, unset, cp, mv. I hope the names are self-explanatory. These may become handy in some specific situations, mostly when scripting version bumps.
  3. It does not alter comments and empty lines when editing a file. It only produces a minimal diff of the modified key. This eases the review of code changes done using the tool.

I use it daily. If you have the same needs as me, feel free to have a look at ym!

← back home