sincecutoff.com
← all changes

yq adds jq-style conditional operator

Introduced 2026-09-29 · score 0.97

HOW TO USE IT

When transforming YAML or another supported input with yq v4.54.1, use the jq-style `if … then … elif … else … end` expression to choose a result by condition.

yq 'if <condition> then <result> elif <condition> then <result> else <result> end' <input-file>

WHY THIS HELPS

Evaluate a jq-style conditional expression while transforming YAML or other supported data.

BEFORE THIS CHANGE

The official tips page says to combine `with` and `select` to approximate if/elif/else logic; it notes that the approach has no `else` concept and may require extra logic.

REQUIREMENTS AND LIMITATIONS

  • Version: v4.54.1
  • if <condition> (required): Begins the conditional and supplies the first condition. The v4.54.1 release note documents the operator; detailed condition semantics were not found.
  • then <result> (required): Supplies the result for the preceding condition. Detailed result semantics were not found.
  • elif <condition> then <result>: Adds a further condition and its result; the release note names `elif` as part of the operator. Detailed behavior was not found.
  • else <result> (required): Supplies the alternative result; the release note names `else` as part of the operator. Detailed behavior was not found.
  • end (required): Closes the conditional expression.
  • <input-file> (required): Input file to process; yq also supports reading input from standard input.
  • Prerequisite: Use yq v4.54.1 or later for the conditional operator; the release note announces it in v4.54.1.
  • Prerequisite: Install or otherwise have the yq command available; the README describes it as a standalone command-line processor.
  • Docs conflict: The tips page says yq had not yet added if expressions, but it predates v4.54.1 and conflicts with the v4.54.1 release note. Use the release note for the new operator's availability.

FIRST-PARTY EVIDENCE

Check the installed version and the source before using it. Entry JSON

Report a problem with this card