Created 04-16-2024 12:05 PM
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.
Created 04-16-2024 01:52 PM
Hello Ma'am,
This recordPath would work-
../goodIdentifications[*][./goodIdentificationTypeId = "SKU"]/idValue
[*] is used to iterate a list and * is used to refer to all the keys of a map in RecordPath.
Created 04-16-2024 12:28 PM
@gurveen Welcome to the Cloudera Community!
To help you get the best possible solution, I have tagged our NiFi expert @steven-matison who may be able to assist you further.
Please keep us updated on your post, and we hope you find a satisfactory solution to your query.
Regards,
Diana Torres,Created 04-16-2024 01:52 PM
Hello Ma'am,
This recordPath would work-
../goodIdentifications[*][./goodIdentificationTypeId = "SKU"]/idValue
[*] is used to iterate a list and * is used to refer to all the keys of a map in RecordPath.