Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nifi Merge Json Files Then Turn into JsonArray

Tags:

apache-nifi

Is there a processor / flow I am not considering when wanting to convert JsonMessages merged together (using MergeContent) into a JsonArray? I wanted to try to build JsonArrays from Multiple files and then pass to the QueryRecord to run SQL. Good chance I am missing an out of the box/ obvious way to do that. Any help would be greatly appreciated.

I could use a groovy execute script, but was wanting to avoid custom code, if possible. Thanks!

Messages In -> MergeContent -> ConvertToJsonArray -> QueryRecord.

like image 606
scarpacci Avatar asked Oct 27 '17 16:10

scarpacci


1 Answers

You can use MergeContent and set the Delimiter Strategy to "Text" and then enter [ , ] for the header, demarcator, and footer respectively.

That will insert the header at the beginning of the flow file, the demarcator between every flow file, and the footer at the end.

Alternatively, since it looks like you are using the record stuff, the latest release should have a MergeRecord processor which handle this for you if you used a JsonTreeReader and JsonRecordSetWriter.

like image 67
Bryan Bende Avatar answered Jan 02 '23 21:01

Bryan Bende