Support Questions

Find answers, ask questions, and share your expertise

Possible RecordPath to fetch data from a list based on a condition in NiFi

avatar
New Contributor

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.

1 ACCEPTED SOLUTION

avatar
New Contributor

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.

View solution in original post

2 REPLIES 2

avatar
Community Manager

@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,
Community Moderator


Was your question answered? Make sure to mark the answer as the accepted solution.
If you find a reply useful, say thanks by clicking on the thumbs up button.
Learn more about the Cloudera Community:

avatar
New Contributor

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.