简体   繁体   中英

NiFi How to get updated JSON value in UpdateAttribute processor?

I have following workflow:

ConsumeKafkaData->EvaluateJsonFlow->UpdateRecord->Putfile.

I am having following simple JSON message: {"name":"Yeshwant","active":false}

In EvaluateJsonPath, I created one attribute "name" in configuration which is linked to "name" attribute of above json data.

In UpdateAttribute processor, I created one rule that when value of "name" equals to "dummy" then changed to "funny". I am able to change the value of attribute "name" to value "funny". But the input and output json data did not channge. why? How does UpdateAttribute changes data in JSON directly? is there any configuration I am missing?

Even at PutFile processor I don't see json data changed.

Thanks Yeshwant

In the existing flow you are changing the value of the attribute associated to the flowfile not the actual content of the flowfile.

After UpdateAttribute processor use AttributesToJson processor and recreate your Output JSON content.

Flow:

1. ConsumeKafkaData
2. EvaluateJsonFlow //Extract all json data attributes as flowfile attributes
3. UpdateAttribute 
4. AttributeToJSON //AttributesList -> name,active; Destination -> flowfile Content
5. Putfile

For more details/usage of AttributesToJSON processor refer to this link.

In addition you can use Record oriented processors for this case ie UpdateRecord/QueryRecord processor then use LiteralValue strategy and use Expression language if-else on the value of name attribute.

In case if you are using QueryRecord processor then write a case statement in your sql query.

Refer this link for more details/usage updateRecord processor.

Refer this link for more details/usage of QueryRecord processor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM