mirror of
https://github.com/taigrr/yq
synced 2025-01-18 04:53:17 -08:00
1.3 KiB
1.3 KiB
Updates the LHS using the expression on the RHS. Note that the RHS runs against the original LHS value, so that you can evaluate a new value based on the old (e.g. increment).
Examples
Update parent to be the child value
Given a sample.yml file of:
a:
b:
g: foof
then
yq eval '.a |= .b' sample.yml
will output
{a: {g: foof}}
Update string value
Given a sample.yml file of:
a:
b: apple
then
yq eval '.a.b |= "frog"' sample.yml
will output
{a: {b: frog}}
Update selected results
Given a sample.yml file of:
a:
b: apple
c: cactus
then
yq eval '.a[] | select(. == "apple") |= "frog"' sample.yml
will output
{a: {b: frog, c: cactus}}
Update array values
Given a sample.yml file of:
- candy
- apple
- sandy
then
yq eval '.[] | select(. == "*andy") |= "bogs"' sample.yml
will output
[bogs, apple, bogs]
Update empty object
Given a sample.yml file of:
'': null
then
yq eval '.a.b |= "bogs"' sample.yml
will output
{a: {b: bogs}}
Update empty object and array
Given a sample.yml file of:
'': null
then
yq eval '.a.b[0] |= "bogs"' sample.yml
will output
{a: {b: [bogs]}}