From 4ce6cfff28d5f69777bb64fe94be01aefeac7939 Mon Sep 17 00:00:00 2001 From: Kurt von Laven Date: Mon, 21 Feb 2022 15:50:45 -0800 Subject: [PATCH] Add example for object filter on object. There was already an example for using an object filter on an array. Clarify that object filters can be used on objects as well and that the result is an array, not an object. --- .../learn-github-actions/expressions.md | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/content/actions/learn-github-actions/expressions.md b/content/actions/learn-github-actions/expressions.md index 7409db10e1..14fe4cc00b 100644 --- a/content/actions/learn-github-actions/expressions.md +++ b/content/actions/learn-github-actions/expressions.md @@ -366,4 +366,40 @@ For example, consider an array of objects named `fruits`. ] ``` -The filter `fruits.*.name` returns the array `[ "apple", "orange", "pear" ]` +The filter `fruits.*.name` returns the array `[ "apple", "orange", "pear" ]`. + +You may also use the `*` syntax on an object. For example, suppose you have an object named `vegetables`. + +```json + +{ + "scallions": + { + "colors": ["green", "white", "red"], + "ediblePortions": ["roots", "stalks"], + }, + "beets": + { + "colors": ["purple", "red", "gold", "white", "pink"], + "ediblePortions": ["roots", "stems", "leaves"], + }, + "artichokes": + { + "colors": ["green", "purple", "red", "black"], + "ediblePortions": ["hearts", "stems", "leaves"], + }, +} +``` + +The filter `vegetables.*.ediblePortions` could evaluate to: + +```json + +[ + ["roots", "stalks"], + ["hearts", "stems", "leaves"], + ["roots", "stems", "leaves"], +] +``` + +Since objects don't preserve order, the order of the output can not be guaranteed.