Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

How to handle json using EvaluateJsonPath processor in NiFi

avatar
Expert Contributor

I want to split and transfer the json data in NiFi, Here is my json structure look like this; I want to split json by id1,id2 array of json transfer to respective processor group say example processor_group a,b. I tried with evaluate json path $.id1,$.id2 but i didn't get exact solution. Can you please help me out from this issue;

{
"id1": [{
"u_name": "aa"
}, {
"addr": "bb"
}],
"id2": [{
"u_name": "aa"
}, {
"addr": "bb"
}]
}

 

1 REPLY 1

avatar
Super Guru

@varun_rathinam Accessing json in an array object via EvaluateJsonPath can be quite confusing.   I also notice the structure of your json is kind of confusing with same values in both.  I have adjusted id2 for cc and dd for testing so that I can tell id1 and id2 values apart.

 

The solution you want is (see template for exact string values):

 

Screen Shot 2020-05-04 at 10.20.12 AM.png

 

Screen Shot 2020-05-04 at 10.19.46 AM.png

 

 

 

 

Notice we use the normal tree for each json object ( $.object ) then access the array ( 0, 1 ) then access the array's objects.   Also notice it is possible to access the json object array with or without a . before the [.

 

Reference:

https://community.cloudera.com/t5/Support-Questions/how-to-extract-fields-in-flow-file-which-are-sur...

 

You can also find my template during testing of your issue on my GitHub:

https://github.com/steven-dfheinz/NiFi-Templates/blob/master/NiFI_EvaluateJsonPath_Demo.xml

 

 

If this answer resolves your issue or allows you to move forward, please choose to ACCEPT this solution and close this topic.   If you have further dialogue on this topic please comment here or feel free to private message me.    If you have new questions related to your Use Case please create separate topic and feel free to tag me in your post.

 

Thanks,


Steven @ DFHZ