cancel
Showing results for 
Search instead for 
Did you mean: 

Expression Library - navigating JSON arrays

reuben
New Contributor

I would like to create an expression library that traverses a JSON array, but I am unsure of the syntax as it does not seem to match what I usually use in a pipeline (JSONPath).

Say I have "LateralSize" in one parameter and the following in the second parameter: 

 

[{
"CustomFieldId": "68f40528-4d63-6a70-60d6-0797407c53d7",
"CustomFieldLayoutControlType": 2,
"FieldName": "LateralSize",
"Label": "Lateral Size",
"PickListItems": [
{
"CustomFieldPickListItemID": "28bd8b11-dfd5-f514-a694-320be7078e59",
"Value": "5",
"Order": 1
},
{
"CustomFieldPickListItemID": "2b58d501-5584-bfbb-a622-54778262cf3f",
"Value": "6",
"Order": 2
}
],
"Value": "2b58d501-5584-bfbb-a622-54778262cf3f",
},
{
"CustomFieldId": "09a0e02d-ae97-431e-74b6-4ea9ecdd742d",
"FieldName": "StreetofConnection",
"Label": "Street of Connection",
"Value": "asdf"
}
] 

 

I would like to get the 6 in the value field.  Each value of the custom field has a guid.  I need to match the actual value in the custom field guid to the CustomFieldPickListItemID.

In other words, I find the guid found in 

"Value": "2b58d501-5584-bfbb-a622-54778262cf3f",

and then match it up to the 

"CustomFieldPickListItemID": "2b58d501-5584-bfbb-a622-54778262cf3f"

Then, I would like to return what is in the value field in that item - 6.

Any ideas will be appreciated.

2 REPLIES 2

endor_force
New Contributor III

You can do it in mapper by using this code, which probably can be partially or fully moved in to an expression library function also with some tinkering.

 If the document has PickListItems
Then Filter out the element where CustomFieldPickListItemID is = to $Value of the document, returns the first found value of $PickListItems.Value found. 
If it does not have PickListItems it returns empty string

$.hasPath("PickListItems") ? ($PickListItems.filter((PickListItem) => PickListItem.CustomFieldPickListItemID== $Value ))[0].Value :  ''

 

How are $PickListItems and PickListItem defined?  Would that need to be done in separate mapper?

if $CustomFields is defined as the array above, I had to use two mappers:

One to get the value and one to get the field itself (item in the custom fields array):

$servicesizefield: jsonPath($, "CustomFields[*]").find(x=>x.FieldName=="ServiceTypeSize")

$servicesizevalueid: jsonPath($, "CustomFields[*]").find(x=>x.FieldName=="ServiceTypeSize").Value

then 

jsonPath($,"$servicesizefield.PickListItems[*]").find(x=>x.CustomFieldPickListItemID==$servicesizevalueid).Value

 to get the actual value at that id.

How would I adapt that to expression library as jsonpath doesn't seem to work at all?