[ 
https://issues.apache.org/jira/browse/NIFI-14687?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18017652#comment-18017652
 ] 

Oleksandr Shpak commented on NIFI-14687:
----------------------------------------

[~exceptionfactory] Yes. However for the use case that I mentioned in my 
original requests neither "JoltTransformJSON" nor "JSLTTransformJSON" 
processors are not so efficient and easy to use, especially when you need to 
template the value.

Let me add more clarity. For instance, I've called two API endpoints and got 
the structures:
{code:java}
// Response one
{
  "user": { "name": "Mr. Bean", "active": false }
}{code}
{code:java}
// Response two
{
  "item": {
    "status": "available"
  }
}{code}
According to the business logic, if user is inactive, the item status should be 
set to "unavailable".

So, in this case I have to use "EvaluateJsonPath" Processor to extract 
$.user.active and $.item.status values, and using the new Processor to set the 
update rule like this
{code:java}
Key name: $.item.status
Value: ${activeUser:ifElse(${currentItemStatus}, "unavailable")}{code}
Simple? Easy? I think so. Compare this approach with JOLT and JSLT variants.

 

> New processor to modify flow file content in JSON format
> --------------------------------------------------------
>
>                 Key: NIFI-14687
>                 URL: https://issues.apache.org/jira/browse/NIFI-14687
>             Project: Apache NiFi
>          Issue Type: Wish
>          Components: Extensions
>    Affects Versions: 2.4.0
>            Reporter: Oleksandr Shpak
>            Priority: Trivial
>
> h2. Use case
> In case when user need to modify JSON flow file content and set the new 
> values of some keys using attribute values, currently it's possible with 
> external scripts or complex schemas only.
> Example. NiFi calls external API, get the result in JSON format. Then calls 
> another API endpoint to get the recent object status. After that the recent 
> status should be set to the specific key (by path) in the original response.
> h2. Processor requirements
>  * Processor should modify JSON content only
>  * User can define one or more attribute names which values will be used to 
> update the flow file content
>  * For every attribute name user should set the path in JSONPath format
>  * Processor should accept the next additional parameter:
>  ** Processing behavior:
>  *** Ignore empty or unset attribute values.
>  *** Assign null value if attribute value is empty or not set



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to