my initial thought here for you would be to chain the following three NiFi processor components together: --> EvaluateJsonPath ---> UpdateAttribute ---> UpdateRecord -->
1. The EvaluateJsonPath processor should be configured to write the desired Json field value out to a NiFi FlowFileAttribute. 2. The UpdateAttribute processor would be used to manipulate that extracted value by subtracting 30 from it using the NiFi Expression Language (EL) 3. The UpdateRecord processor would be used to update your original FlowFile JSON content with the new Json field value.
Out of your EvaluateJsonPath processor your FlowFile now has an attribute with the name "COUNTFILES" and a numeric value? You can confirm this by stopping the UpdateAttribute processor and allowing a test FlowFile to queue on the connection between EvaluateJsonPath and UpdateAttribute processors. Then right click on connection and select "list queue" from the displayed context menu. Then click on the "view details" icon to the far left of row for your listed FlowFile. Within the FlowFile details UI you can inspect the attributes set on this FlowFile.
Then start only the UpdateAttribute processor while UpdateRecord is still stopped and repeat above to verify that updateAttribute processor modified the attribute value.
Writing to the content will overwrite all the other content which is not what I think you want to be doing. Plus the updateAttribute processor can only manipulate FlowFile attributes via the NiFi Expression Language (EL).
So you need to extract the json value to a FlowFile attribute in the EvaluateJsonPath processor. Then manipulate that attributes value and then use UpdateRecord to update the actual content of your FlowFile using that FlowFile's attribute.
I'm okay with writing over the content of the rest of the file. I'm trying to output the rowcount results in a putemail so I'm okay with overwriting the rest of the flowfile. Can you still help with this?
No problem. At this point you have extracted the the count successfully and used updateAttribute processor to subtract 31 from it. You do not need to write it back to the content to use it in putEmail processor.
The majority of the putEmail processor configuration properties support NiFi Expression Language also. You can retrieve the value of your FlowFiiles attribute with this simple NiFi EL statement:
So you can use above anywhere in the string you configure in the the "Subject" and/or "Message" configuration properties.
If you found my answer help you to a solution, please don't forget to mark it as the accepted solution.