#match
Matches a value against cases from top to bottom and returns the value of the first one that matches.
"#match(source as @variable) into 'name'": [ { "case": "result" }, ... ]Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
source |
path | value |
The value to match. |
@variable |
variable |
Bound to the value for use in cases. |
Returns
Section titled “Returns”any
Examples
Section titled “Examples”Match an array shape
Section titled “Match an array shape”{ "somePath": [ 1, 2 ]}{ "#match($.somePath as @x) into 'result'": [ { "#is([])": "'Found an empty array'" }, { "#is([_])": "'Found an array with one or more elements'" }, { "#default()": "'Found something else'" } ]}{ "result": "Found an array with one or more elements"}