Possible RecordPath to fetch data from a list based on a condition in NiFi
Hi Everyone,
I am trying to perform some data transformations using UpdateRecord processor.
The input format is a nested JSON, and I am able to perform shifting of some fields using RecordPath.
But facing issues when preparing a field using some conditional logic from a nested list.
Here is my scenario:
Input JSON
[
{
"orderId": "1234",
"orderName": "Order 1",
"orderItems": [
{
"orderItemSeqId": "01",
"itemStatusId": "ITEM_APPROVED",
"orderItemQuantity": 1,
"unitPrice": 149,
"goodIdentifications": [
{
"goodIdentificationTypeId": "SHOPIFY_PROD_ID",
"idValue": "43623074824370"
},
{
"goodIdentificationTypeId": "SKU",
"idValue": "2510524-4BB-S"
},
{
"goodIdentificationTypeId": "UPCA",
"idValue": "2510524-4BB-S"
}
]
},
{
"orderItemSeqId": "02",
"itemStatusId": "ITEM_APPROVED",
"orderItemQuantity": 1,
"unitPrice": 159,
"goodIdentifications": [
{
"goodIdentificationTypeId": "SHOPIFY_PROD_ID",
"idValue": "43623074824370"
},
{
"goodIdentificationTypeId": "SKU",
"idValue": "2510524-4BB-S"
},
{
"goodIdentificationTypeId": "UPCA",
"idValue": "2510524-4BB-S"
}
]
}
]
}
]The output expected is below:
- New field "itemSku" should be added to each object of orderItems list which is fetched from the goodIdentifications list with goodIdentificationTypeId as SKU.
Expected Output JSON
[
{
"orderId": "1234",
"orderName": "Order 1",
"orderItems": [
{
"orderItemSeqId": "01",
"itemStatusId": "ITEM_APPROVED",
"orderItemQuantity": 1,
"unitPrice": 149,
"goodIdentifications": [
{
"goodIdentificationTypeId": "SHOPIFY_PROD_ID",
"idValue": "43623074824370"
},
{
"goodIdentificationTypeId": "SKU",
"idValue": "2510524-4BB-S"
},
{
"goodIdentificationTypeId": "UPCA",
"idValue": "2510524-4BB-S"
}
],
"itemSku": "2510524-4BB-S"
},
{
"orderItemSeqId": "02",
"itemStatusId": "ITEM_APPROVED",
"orderItemQuantity": 1,
"unitPrice": 159,
"goodIdentifications": [
{
"goodIdentificationTypeId": "SHOPIFY_PROD_ID",
"idValue": "43623074824371"
},
{
"goodIdentificationTypeId": "SKU",
"idValue": "2510524-4BB-T"
},
{
"goodIdentificationTypeId": "UPCA",
"idValue": "2510524-4BB-T"
}
],
"itemSku": "2510524-4BB-T"
}
]
}
]
I would like to know if performing such conditional logic is possible and what could be the possible RecordPath to prepare this field??
Tried something like,
Added new property in UpdateRecord.
Property - /orderItems[*]/itemSku
Value - ../goodIdentifications[./goodIdentificationTypeId = ‘’SKU"]/idValue
But this doesnt seem to work.
Any help would be appreciated.
Thank you.

