Apache Nifi - get the file attributes and construct the json through custom processor

3.6k views Asked by At

I am using a custom processor for csv to json conversion which converts the csv file data into a json array which contains json objects of the data.

My requirement is to get the file attributes like filename, uuid, path etc. and construct a json from these.

Question:

How can I get the related attributes of the file and construct the a json object appending it to the same json getting constructed before.

Just been few days working with apache nifi, so just going with the exact requirements now with the custom processor.

1

There are 1 answers

1
mattyb On BEST ANSWER

I can't speak to which attributes are being written for your custom processor, but there is a set of core attributes that most/all flow files have, such as filename and uuid. If you are using GetFile or ListFile/FetchFile to read in your CSV file, you will have those and a number of other attributes available (see the doc for more info).

When you have a flow file that has the appropriate attributes set, you can use the AttributesToJSON processor to create a JSON object containing a flat list of the specified attributes, and that object can replace the flow file content or become its own attribute (named 'JSONAttributes') depending on the setting of the "Destination" property of AttributesToJSON.