Member since
05-20-2021
1
Post
1
Kudos Received
0
Solutions
05-20-2021
06:17 AM
1 Kudo
Not all credit goes to me but I was pointed to a better simpler way to achieve this. There are 2 ways. Solution 1 - and the simplest and elegant Use Nifi JoltTransformJSON Processor. The processor can make use of Nifi expression language and attributes in both left or right hand side of the specification syntax. This allows you to quickly use the JOLT default spec to add new fields (from flow-file attributes) to a new or existing JSON. Ex: {"customer_id": 1234567, "vckey_list": ["test value"]} both of those fields values are stored in flow-file attributes as a result of a EvaluateJSONPath operation. Assume "customer_id_attr" and ""vckey_list_attr". We can simply generate a new JSON from those flow-file attributes with the "default" jolt spec and the right hand syntax. You can even add addition expression language functions to the processing [
{
"operation": "default",
"spec": {
"customer_id": ${customer_id_attr},
"vckey_list": ${vckey_list_attr:toLower()}
}
}
] This worked for me even when storing the entire JSON, path of "$", in a flow-file attribute. Solution 2 - complicated and uglier Use a sequence Nifi ReplaceText Processor. First use a ReplaceText processor to append the desired flow-file attribute to the file-content. If you are generating a totally new JSON, this would do it. If you are trying to modify an existing one, you would need to first append the desired keys, than use ReplaceText again to properly format as a new key in the existing JSON, from {"original_json_key": original_json_obj}{"customer_id": 1234567, "vckey_list": ["test value"]} to {"original_json_key": original_json_obj, "customer_id": 1234567, "vckey_list": ["test value"]} using Then use JOLT to do further processing (that's why Sol 1 always makes sense) Hope this helps, spent about half a day figuring out the 2nd Solution and was pointed to Solution 1 by someone with more experience in Nifi
... View more