5

I have a flow that creates some new attributes / content. I want to take an attribute from the flow files, and add it into the JSON content of the file.

I can use AttributesToJSON, but that just overwrites the file content.

A sample of my flow is here:

enter image description here

The UpdateAttribute adds current time to the attribute list, and then the AttributestoJSON adds an attribute to the actual JSON, but it also overwrites the entire flow file content. I've tried to remedy this with MergeRecord, but I can't the two files to merge back together (using CurrentTime as a Correlation Attribute Name).

Is there a better to go about this? The MergeRecord just comes up with an error. (Also not sure how to configure the RecordReader/Writer, because I want to keep everything in JSON).

papelr
  • 468
  • 1
  • 11
  • 42

1 Answers1

12

Use UpdateRecord and add a property where the name is the field you want to update like "/currentTime" and the value is the expression language reference to the attribute like ${currentTime}, assuming you set currentTime in UpdateAttribute.

Bryan Bende
  • 18,320
  • 1
  • 28
  • 39
  • So I was really reaching towards complexity for no reason... I'm dumb. Thanks for the help! – papelr Nov 08 '18 at 01:34
  • 1
    Question: I want to keep it JSON, so for the reader/writers, what's the best method? JSONTree or Path? – papelr Nov 08 '18 at 15:10
  • 2
    JsonTreeReader, you would only use JsonPathReader if you want to specify specific paths from the json, the tree reader just reads everything – Bryan Bende Nov 08 '18 at 15:43
  • is there a way to write into a nested object within the target json. Something like /currentTime/bar – Harald Thomson Oct 25 '22 at 12:48