Skip to content

Node value copied into a sequence cannot be deleted #2269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jandubois opened this issue Jan 25, 2025 · 1 comment
Open

Node value copied into a sequence cannot be deleted #2269

jandubois opened this issue Jan 25, 2025 · 1 comment

Comments

@jandubois
Copy link
Contributor

macOS 15.2

$ yq --version
yq (https://github.com/mikefarah/yq/) version v4.45.1

When a node value is copied into a sequence, it cannot be deleted:

$ echo 'foo: bar' | yq '.a = [.foo, "baz"] | .b = ["bar", "baz"] | del(.a[0], .b[0])'
foo: bar
a:
  - bar
  - baz
b:
  - baz

The additional literal sequence elements can be deleted normally:

echo 'foo: bar' | yq '.a = [.foo, "baz"] | .b = ["bar", "baz"] | del(.a[1], .b[1])'
foo: bar
a:
  - bar
b:
  - bar
@jandubois
Copy link
Contributor Author

Workaround: concatenate with the empty string (note: the order matters!)

echo 'foo: bar' | yq '.a = ["" + .foo, "baz"] | .b = ["bar", "baz"] | del(.a[0], .b[0])'
foo: bar
a:
  - baz
b:
  - baz

Just showing that the concatenation produces the correct string value:

echo 'foo: bar' | yq '.a = ["" + .foo, "baz"] | .b = ["bar", "baz"] | del(.a[1], .b[1])'
foo: bar
a:
  - bar
b:
  - bar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant