Field Value Selector
The goal of the Field Value Selector is to identify the value of a particular field in each of the records in the array selected by the Record Selector. The input to the expression is an individual record from the array.
Using the above example responses in which each property has a single scalar (i.e., string, number, or boolean) value:
{"name": "Seattle", "state": "WA"}
The Field Value Selector is going to be just the name of the property within the object (e.g., name
or state
).
There are also many common variations.
Property is an array:
{"stooges": ["Larry", "Curly", "Moe"]}
For all values:
stooges[*]
For just the first value:
stooges[0]
For just the last value:
stooges[-1]
Property is an object:
{"name": {"first": "John", "middle": "Paul", "last": "Jones"}}
This is a slightly harder case because Studio fields can only be a scalar value or an array of scalar values, so you need to decide on a case-by-case basis the strategy you want to use to represent the property. The most common strategy would be to flatten the structure by defining separate record fields for each of the sub-properties, as follows:
field givenName:
name.first
field middleName:
name.middle
field surname:
name.last
Property is an array of objects (this is common in Google Directory API):
{ "phones": [ {"value": "+18005551212", "type": "work"}, {"value": "+1800COLLECT", "type": "home"}, ] }
This is even harder, but there are strategies that can work, such as:
flatten based on some key property
field workPhone:
phones[?type == 'work'].value
field homePhone:
phones[?type == 'home'].value
flatten and extract arrays of each sub-property in which you are interested
field phoneValues:
phones[].value
which gives
["+18005551212", "+1800COLLECT"]
field phoneTypes:
phones[].type
which gives
["work", "home"]
extract arrays of combined properties
field phones:
phones[].join(':', [type, value])
which gives
["work:+18005551212", "home:+1800COLLECT"]
just pulling in as an array of JSON strings that can be parsed by a value template expression (JavaScript) further down the line
field phones:
phones[].to_string(@)
which gives
["{\"value\": \"+18005551212\", \"type\": \"work\"}", "{\"value\": \"+1800COLLECT\", \"type\": \"home\"}"]