Support Questions

Find answers, ask questions, and share your expertise

traverse list of strings of flow attribute in JoltTransformJson processor nifi

avatar
Explorer

Hello Everyone,

 

Greetings!

 

I need help in JoltTransformJson processor.

I have GALLERY_IDS string in flow attribute as mentioned in the below screenshot:

sahil0915_0-1663565693454.png

I want to fetch each value from GALLERY_IDS attribute and pass it to JoltTransformJson processor as mentioned in below snapshot

sahil0915_1-1663565752903.png

 

In the output queue, I should get flow file for each gallery with personid.

{"GALLERY_ID:"1","PERSON_ID":"test1"}

{"GALLERY_ID:"2","PERSON_ID":"test2"}

{"GALLERY_ID:"3","PERSON_ID":"test3"}

{"GALLERY_ID:"4","PERSON_ID":"test4"}

{"GALLERY_ID:"5","PERSON_ID":"test5"}

{"GALLERY_ID:"6","PERSON_ID":"test6"}

{"GALLERY_ID:"7","PERSON_ID":"test7"}

 

Kindly help.

 

Thanks in advance!

1 REPLY 1

avatar
Super Guru

Hi,

Is your input in Json format? if its json do you need to completely replace it with the output you specified? If that is the case then you dont need Jolt transformation, instead you can do the following:

1- Place the Gallery_Ids attribute as flowfile content. You can do that using the ReplaceText processor where the Replacement Value is the attribute ${GALLERY_IDS}

2- Do SplitJson to split the Array into a different flow file, this should give 7 flowfiles with the values: 1,2,3,4,5,6 & 7

3- Add another ReplaceText processor that will capture each split from above and replace the flowfile content with the following template in the Replacement Value:

{"GALLERY_ID":"$1","PERSON_ID":"test$1"}

Leave the Search Value as (?s)(^.*$)

This should again give you 7 flowfiles with the expected output format.

 

Hope that helps, if it does please accept solution.

Thanks