cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Retrieving the value of a sibling from a JSON payload

Toby
New Contributor II

Hi, Iโ€™m trying to extract the object_id of the object with path=โ€œ/Test_Engagement_A17โ€ and write this to a pipeline property in a Mapper. Could anyone give me a pointer? Thanks.

โ€œobjectsโ€: [
{
โ€œobject_typeโ€: โ€œDIRECTORYโ€,
โ€œpathโ€: โ€œ/Test_Engagement_A19โ€,
โ€œobject_idโ€: 665165640133153
},
{
โ€œobject_typeโ€: โ€œDIRECTORYโ€,
โ€œpathโ€: โ€œ/Test_Engagement_A17โ€,
โ€œobject_idโ€: 4163760986883599
},
{
โ€œobject_typeโ€: โ€œDIRECTORYโ€,
โ€œpathโ€: โ€œ/Test_Engagement_A18โ€,
โ€œobject_idโ€: 4163760986883600
}
]
}

1 ACCEPTED SOLUTION

cjhoward18
Employee
Employee

In a mapper you can use this expression:
$objects.find(entry => entry.path == "/Test_Engagement_A17").object_id

to find the first entry with that path. If there is a chance there is more than one you may want to use this expression to collect all matches which will result in an array of object_id values:

jsonPath($objects, "[?(value.path == '/Test_Engagement_A17')].object_id")

View solution in original post

2 REPLIES 2

cjhoward18
Employee
Employee

In a mapper you can use this expression:
$objects.find(entry => entry.path == "/Test_Engagement_A17").object_id

to find the first entry with that path. If there is a chance there is more than one you may want to use this expression to collect all matches which will result in an array of object_id values:

jsonPath($objects, "[?(value.path == '/Test_Engagement_A17')].object_id")

Toby
New Contributor II

Exactly what I needed, thanks.