Nifi Merge Json Files Then Turn into JsonArray
Asked Answered
N

1

6

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.

Need answered 27/10, 2017 at 16:21 Comment(0)
K
13

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.

Kumquat answered 27/10, 2017 at 16:27 Comment(3)
awesome. Worked great. Thanks!Need
What if I wanted to separate json by a new line? I typed \n in the demarcator but it prints a '\n'Rove
Use shift+enter to make a new line for the demarcator, or use MergeRecord and set the JsonRecordSetWriter to per-lineKumquat

© 2022 - 2024 — McMap. All rights reserved.