From b06ab987b1b2852d002fbe2be428896d159a0827 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Tue, 26 Sep 2023 14:50:18 +1000 Subject: [PATCH] v4.35.2 --- how-it-works.md | 2 +- operators/group-by.md | 2 +- operators/pick.md | 4 ++-- usage/csv-tsv.md | 2 +- usage/shellvariables.md | 4 ++-- usage/xml.md | 19 +++++++++++++++++++ 6 files changed, 26 insertions(+), 7 deletions(-) diff --git a/how-it-works.md b/how-it-works.md index 51a41fcd..f77a4cd9 100644 --- a/how-it-works.md +++ b/how-it-works.md @@ -29,7 +29,7 @@ It pipes the current, lets call it 'root' context through the `lhs` expression o cat ``` -Sidenote: this node holds not only its value 'cat', but comments and metadata too, including path and parent information. +Side note: this node holds not only its value 'cat', but comments and metadata too, including path and parent information. The `=` operator then pipes the 'root' context through the `rhs` expression of `.b` to return the node diff --git a/operators/group-by.md b/operators/group-by.md index f5169b72..c06b273e 100644 --- a/operators/group-by.md +++ b/operators/group-by.md @@ -26,7 +26,7 @@ will output bar: 100 ``` -## Group by field, with nuls +## Group by field, with nulls Given a sample.yml file of: ```yaml - cat: dog diff --git a/operators/pick.md b/operators/pick.md index 3b477699..fbe9bd95 100644 --- a/operators/pick.md +++ b/operators/pick.md @@ -13,7 +13,7 @@ myMap: cat: meow dog: bark thing: hamster - hamster: squeek + hamster: squeak ``` then ```bash @@ -22,7 +22,7 @@ yq '.myMap |= pick(["hamster", "cat", "goat"])' sample.yml will output ```yaml myMap: - hamster: squeek + hamster: squeak cat: meow ``` diff --git a/usage/csv-tsv.md b/usage/csv-tsv.md index c58e42cd..70331a2b 100644 --- a/usage/csv-tsv.md +++ b/usage/csv-tsv.md @@ -2,7 +2,7 @@ Encode/Decode/Roundtrip CSV and TSV files. ## Encode -Currently supports arrays of homogenous flat objects, that is: no nesting and it assumes the _first_ object has all the keys required: +Currently supports arrays of homogeneous flat objects, that is: no nesting and it assumes the _first_ object has all the keys required: ```yaml - name: Bobo diff --git a/usage/shellvariables.md b/usage/shellvariables.md index a2919715..ba50315a 100644 --- a/usage/shellvariables.md +++ b/usage/shellvariables.md @@ -34,7 +34,7 @@ Given a sample.yml file of: ascii_=_symbols: replaced with _ "ascii_ _controls": dropped (this example uses \t) nonascii_א_characters: dropped -effrot_expeñded_tò_preserve_accented_latin_letters: moderate (via unicode NFKD) +effort_expeñded_tò_preserve_accented_latin_letters: moderate (via unicode NFKD) ``` then @@ -46,7 +46,7 @@ will output ascii___symbols='replaced with _' ascii__controls='dropped (this example uses \t)' nonascii__characters=dropped -effrot_expended_to_preserve_accented_latin_letters='moderate (via unicode NFKD)' +effort_expended_to_preserve_accented_latin_letters='moderate (via unicode NFKD)' ``` ## Encode shell variables: empty values, arrays and maps diff --git a/usage/xml.md b/usage/xml.md index 89bee794..2d469450 100644 --- a/usage/xml.md +++ b/usage/xml.md @@ -128,6 +128,25 @@ zoo: - cat ``` +## Parse xml: force all as an array +Because of the way yq works, when updating everything you need to update the children before the parents. By default `..` will match parents first, so we reverse that before updating. + +Given a sample.xml file of: +```xml +boing +``` +then +```bash +yq -oy '([..] | reverse | .[]) |= [] + .' sample.xml +``` +will output +```yaml +- zoo: + - thing: + - frog: + - boing +``` + ## Parse xml: attributes Attributes are converted to fields, with the default attribute prefix '+'. Use '--xml-attribute-prefix` to set your own.