mikefarah / yq

yq is a portable command-line YAML, JSON, XML, CSV, TOML and properties processor
https://mikefarah.gitbook.io/yq/
MIT License
12.36k stars 602 forks source link

Replace with_entries broken #2050

Closed alexpenev-s closed 5 months ago

alexpenev-s commented 6 months ago

Version of yq: v4.44.1

Input Yaml data1.yml:

a:
  b:
    c: 1

Command The command you ran:

yq e  '(.a | with_entries(select(.key | test("b$"))) | .[].c) = "5504881"' data1.yml

Actual behavior

a:
  b:
    c: 1

Expected behavior

a:
  b:
    c: "5504881"

Additional context with yq version 4.22.1 The replace is done corretly.

mikefarah commented 5 months ago

When using with_entries you have to perform the update within the brackets of that operator - not out. To get what you want here, you'd need to do something like:

yq '.a |= with_entries(select(.key | test("b$")) | .value.c = "5504881")' examples/data1.yaml

a:
  b:
    c: "5504881"

Explanation:

alexpenev-s commented 5 months ago

Thank you