Forum Discussion

Toby's avatar
Toby
New Contributor II
5 years ago
Solved

Retrieving the value of a sibling from a JSON payload

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
}
]
}

  • 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")

2 Replies

  • 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's avatar
      Toby
      New Contributor II

      Exactly what I needed, thanks.