diff --git a/bob.yml b/bob.yml deleted file mode 100644 index 8c102531..00000000 --- a/bob.yml +++ /dev/null @@ -1,2 +0,0 @@ -name: bob -age: 23 diff --git a/how-it-works.md b/how-it-works.md index 01fc048f..d5cb5f96 100644 --- a/how-it-works.md +++ b/how-it-works.md @@ -66,20 +66,28 @@ Lets say you had: Lets say you wanted to update the `sally` entry to have fruit: 'mango'. The _incorrect_ way to do that is: `.[] | select(.name == "sally") | .fruit = "mango"`. -Becasue `|` has a low operator precedence, this will be evaluated (_incorrectly_) as : `(.[]) | (select(.name == "sally")) | (.fruit = "mango")`. What you'll see is only: +Becasue `|` has a low operator precedence, this will be evaluated (_incorrectly_) as : `(.[]) | (select(.name == "sally")) | (.fruit = "mango")`. What you'll see is only the updated segment returned: ```yaml name: sally fruit: mango ``` -Returned :( - - -In this case, you will need to use brackets (think BODMAS from maths) and wrap the entire LHS, so the _correct_ expression is: +To properly update this yaml, you will need to use brackets (think BODMAS from maths) and wrap the entire LHS: `(.[] | select(.name == "sally") | .fruit) = "mango"` +Now that entire LHS expression is passed to the 'assign' (`=`) operator, and the yaml is correctly updated and returned: + + +```yaml +- name: bob + fruit: apple +- name: sally + fruit: mango + +``` + ## Relative update (e.g. `|=`) There is another form of the `=` operator which we call the relative form. It's very similar to `=` but with one key difference when evaluating the RHS expression. diff --git a/tim.yml b/tim.yml deleted file mode 100644 index 008b6e31..00000000 --- a/tim.yml +++ /dev/null @@ -1,2 +0,0 @@ -name: tim -age: 17