Skip to content Skip to sidebar Skip to footer

Access Json Element And Write To A Text File Using Python Executescript Processor

I am new to python and nifi. My flow is GetFile-->ExecuteScript In the script, for each json,i want to accesss a particular element and write it to a text file line by line. I

Solution 1:

The body of your Python class is not indented, and neither is the body of the process method. Try indenting one level from the def init line through the outputStream.write line, then again indent one level from the text = IOUtils.toString line through the outputStream.write line, this should give you a working StreamCallback class and cause the script to work correctly.

Also you do not need a call to session.commit(), that will be called for you when the script is complete.

EDIT (due to OP edit -- see comments): The script above is still not indented correctly, the body of the process() method needs to be indented. Are you getting errors or bulletins on the ExecuteScript processor? If the incoming flow files are being queued before ExecuteScript, then the "flowFile = session.get()" is not getting executed, or the processor should be throwing an error and posting a bulletin (a red box on the upper right corner).

Also since you intend to send the same content out of the processor in a flow file, you shouldn't need the "text_file" code, I assume that's for debugging?

Post a Comment for "Access Json Element And Write To A Text File Using Python Executescript Processor"