Support Questions
Find answers, ask questions, and share your expertise

Hi, question in nifi updateattribute processor

New Contributor

I have a processor EvaluateJsonPath processor which is extracting two fields from json file(coming from GETFile processor) which contains

{

"name": "Jon",

"title": "king of the nights watch"

}

after extracting name in EvaluateJsonPath processor as $.name, I want to to write this data to put file processor but before writing I want to change the name of the file such as

name+timestamp, ex: jon_23-06-2021

 

I have tried updateattribute processor something like 

{name}_${now():format('yyyy-MM-dd-HH-mm-ss')}

 

but its not working, could some one help me here

 

thanks

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Hi, question in nifi updateattribute processor

Master Guru

@Mahi123 

 

Just to make sure i understand your use case correctly, you want to change the content only of your NiFi FlowFile?

You have a NiFi FlowFile with following json content:

{
"name": "Jon",
"title": "king of the nights watch"
}

and you want to modify it to:

{
"name": "Jon_<current date>",
"title": "king of the nights watch"
}


I read your statement "I want to change the name of the file" as wanting to edit the filename and not the content of the file itself.  Which is something totally different than above.

Assuming you are looking to modify content and not the filename itself, you can do this using the ReplaceText processor after your EvaluateJsonPath processor.

MattWho_0-1624537112850.png

 

Search Value = ("name": "${name}")
Replacement Value = "name": "${name}_${now():format('yyyy-MM-dd-HH-mm-ss')}"
Replacement Strategy = Regex Replace
Evaluation Mode = Line-by-Line

NiFi typically has more than one way to satisfy the use case and there may be better option than the above using the various available record based processors.  You may want to explore those as well.

If you found this addressed your query, please take a moment to login and click "Accept" on this solution.

Thank you,

Matt

View solution in original post

2 REPLIES 2

Re: Hi, question in nifi updateattribute processor

Master Guru

@Mahi123 

 

Just to make sure i understand your use case correctly, you want to change the content only of your NiFi FlowFile?

You have a NiFi FlowFile with following json content:

{
"name": "Jon",
"title": "king of the nights watch"
}

and you want to modify it to:

{
"name": "Jon_<current date>",
"title": "king of the nights watch"
}


I read your statement "I want to change the name of the file" as wanting to edit the filename and not the content of the file itself.  Which is something totally different than above.

Assuming you are looking to modify content and not the filename itself, you can do this using the ReplaceText processor after your EvaluateJsonPath processor.

MattWho_0-1624537112850.png

 

Search Value = ("name": "${name}")
Replacement Value = "name": "${name}_${now():format('yyyy-MM-dd-HH-mm-ss')}"
Replacement Strategy = Regex Replace
Evaluation Mode = Line-by-Line

NiFi typically has more than one way to satisfy the use case and there may be better option than the above using the various available record based processors.  You may want to explore those as well.

If you found this addressed your query, please take a moment to login and click "Accept" on this solution.

Thank you,

Matt

View solution in original post

Re: Hi, question in nifi updateattribute processor

New Contributor

@MattWho  Thank you so much for responding, 

 

I want to rename the outgoing file as such "name_timestamp". want to name each file with the following standard "name"+"_"+"timestamp"

 

and the issue is solved after changing destination value from flowfile-content to flowfile-attribute

initially it was pointing to flowfile-content and I dont see the custom extracted attributes in attribute section, but after changing to flowfile-attribute, I can see the extracted values in the attribute section

Mahi123_0-1624540620596.png

 

thank you very much