How to conditionally extract a value from a nested array object in AEP Data Prep (ingestion)?
I have a source JSON with an array of objects. Each object has nested fields including an identifier and a code. I need to extract the identifier from the array item where a specific nested field matches a given value.
Example Structure:
{
"items": [
{
"details": {
"id": null,
"type": { "code": "ABC" }
}
},
{
"details": {
"id": "123456",
"type": { "code": "XYZ" }
}
}
]
}Goal: Extract details.id from the array item where details.type.code == "XYZ".
The array length is not fixed — it could have 1 to N items, and the matching item could be at any index.
Current approach (works but not scalable):
coalesce(
iif(items[0].details.type.code == "XYZ", items[0].details.id, null),
iif(items[1].details.type.code == "XYZ", items[1].details.id, null),
iif(items[2].details.type.code == "XYZ", items[2].details.id, null),
null
)
Question:
Is there a cleaner built-in Data Prep function to conditionally filter an array by a nested field value during ingestion? Or is the coalesce/iif per-index approach the only available option?