Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

How to split a flow file and convert sections of it to JSON content using NIFI?

How to split a flow file and convert sections of it to JSON content using NIFI?

I am consuming messages from IBM MQ using Nifi. Each message is 1000 chars long. Based on the index I have to split the flowfile and then add the splits to JSON object.

e.g. 2525252525M123456789JohnDoe
to : {"Phone":"2525252525", "Sex":M, "Ssn":"123456789", "Name":"JohnDoe" }


Is there a way to do this using any of the Nifi processors. The other approach is to use python or some other script to do that and use Execute Processors. But, if there is some other way please let me know.

1 REPLY 1
Highlighted

Re: How to split a flow file and convert sections of it to JSON content using NIFI?

Super Guru

@Chandan Singh

You can use QueryRecord processor for this case and use Apache Calcite sql parser.

-

Add new property to the processor as

select substring(0,9)Phone...etc from FLOWFILE

-

Define Record Reader(csvreader)/Writer(jsonsetwriter) controller services and resultant flowfile from processor will be in JSON format.