Skip to main content
Level 2
April 27, 2026
Solved

How to conditionally extract a value from a nested array object in AEP Data Prep (ingestion)?

  • April 27, 2026
  • 1 reply
  • 68 views

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?

Best answer by giuseppebaglio

Since you're hitting a hard ceiling in Data Prep, consider these alternative solutions:

  • Normalize upstream — Flatten or pre-select the matching item before the payload reaches AEP. If you control the source system or an ETL layer (e.g., via Azure Data Factory, AWS Glue, or a custom webhook), emitting details_XYZ_id as a flat field is the most robust fix.

  • AEP Query Service (post-ingestion) — If the raw array is landing in a dataset, you can use FILTER or TRANSFORM higher-order SQL functions in Query Service to extract the value and write it to a derived dataset. This decouples the transformation from the ingestion mapping.

1 reply

giuseppebaglio
Level 10
April 27, 2026

hi ​@Ankith Menon,

Rather than the coalesce/iif per-index approach, consider using array_to_map, which converts an object array into a map keyed by a field value . This can eliminate index-based hardcoding:

// Step 1: Convert array to a map keyed by the type code
array_to_map(items, "details.type.code")

// Step 2: Access the target entry by key and drill down
array_to_map(items, "details.type.code")["XYZ"].details.id

The resulting map would look like { "ABC": {...}, "XYZ": {...} }, so you can directly retrieve the object for "XYZ" without iterating by index. Note that the KEY parameter supports field names within the array objects — test whether a nested path like "details.type.code" is accepted in your environment, as the docs describe it as "a field name in the object array" .

Level 2
April 28, 2026

hi ​@giuseppebaglio , 

Thank you for providing the method,

but unfortunately, the nested path is not accepted in my environment. (Error transforming data for destination path _._._ Details: Error invoking array_to_map(java.lang.Object[],java.lang.String) caused by : java.lang.NullPointerException). 

I tried using the filterArray function, but as the document mentions, its only a destination only function. Right now, still stuck with coalesce as the only option

giuseppebaglio
giuseppebaglioAccepted solution
Level 10
April 28, 2026

Since you're hitting a hard ceiling in Data Prep, consider these alternative solutions:

  • Normalize upstream — Flatten or pre-select the matching item before the payload reaches AEP. If you control the source system or an ETL layer (e.g., via Azure Data Factory, AWS Glue, or a custom webhook), emitting details_XYZ_id as a flat field is the most robust fix.

  • AEP Query Service (post-ingestion) — If the raw array is landing in a dataset, you can use FILTER or TRANSFORM higher-order SQL functions in Query Service to extract the value and write it to a derived dataset. This decouples the transformation from the ingestion mapping.