Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

How to transform a json array into a string list with nifi

avatar
New Member

Hello,

i have a queryCassandra which generate a json like this one:

{"results":[{"term":"term1"},{"term":"term2"}..]} 

Now, i want to get from this all the terms values separated by some separator in string format;

ex : term1,term2,term3

So i can pass this list as a string parameter for a java main program which i've alreat set.

(i only need the transofrmation, not the java program execution) Thank you !

1 ACCEPTED SOLUTION

avatar

Hello,

I think you can do that with EvaluateJsonPath extracting String in an JSON array, followed by UpdateAttribute removes special characters such as double quotes and square brackets by Expression Language.

Here is an example NiFi template that does above conversion:

https://gist.github.com/ijokarumawak/bd37690ee8aa0bf8e9e2a47cf064e0d4

15654-json-array-to-string-list.png

View solution in original post

5 REPLIES 5

avatar

first you need to validate JSON data , you can use this tool JSON Formatter and JSON Validator

avatar

Hello,

I think you can do that with EvaluateJsonPath extracting String in an JSON array, followed by UpdateAttribute removes special characters such as double quotes and square brackets by Expression Language.

Here is an example NiFi template that does above conversion:

https://gist.github.com/ijokarumawak/bd37690ee8aa0bf8e9e2a47cf064e0d4

15654-json-array-to-string-list.png

avatar
New Member

thanks @kkawamura! a last question, how can i get the flowfile generated as ex : term1,term2,term3 as a parameter in the next processor?

avatar

You mean how to map the attribute value (term1,term2,term3) to FlowFile content? If so, I'd use ReplaceText processor, set Replacement Value as "${attribute-name}" and Replacement Strategy as "Always Replace".

avatar
New Contributor

In my case I have to fetch a particular key value from a json array. I was trying to do $.[key] but it just splits the array into separate json files. Is there any solution for this ? I wanted the split array as {"test1", "test2"}

Jsonarray example: [{"key":"test1", "name":"testName"}, {"key":"test2", "name":"testName2"}]