Skip to main content
divnid
Silver ⭐️
July 28, 2022
Solved

Add flow attribute from Json

Hi, 

I am trying to add flow attribute from my json file which looks like:

[ {
"name" : "id",
"value" : "29879"
}, {
"name" : "file",
"value" : ""
}, {
"name" : "barcode",
"value" : ""
}, {
"name" : "roll no",
"value" : "3032"
}, {
"name" : "name",
"value" : "Daniel"
}]

 

Now I want to add roll no. as a flow atrribute using  evaljson.PNG

 

Can someone please help me with it? Thanks

SAMSAL
SAMSALAnswer
Platinum ⭐️⭐️⭐️
July 28, 2022

Hi ,

If you want to extract the value (3032) of the name "roll no" into flowfile attribute called "roll no" you can accomplish this with two processors as follows:

 

1- EvaluateJsonPath:

    roll no = $.[?(@.name=='roll no')].value

    Make sure the Return Type is set to Json since the exrepssion above will return json ["3032"].

 

SAMSAL_0-1659035286850.png

 

2- Update Attribute : which will extract the actual value from result json above with the following  attribute:   roll no = ${'roll no':jsonPath('$[0]')}

 

SAMSAL_1-1659035395931.png

 

Also you can refer to :

https://community.cloudera.com/t5/Support-Questions/Unable-to-return-a-scalar-value-for-the-expression-from-NIFI/td-p/213677

 

If that helps, please Accept Solution. Thanks

2 replies

SAMSAL
SAMSALAnswer
Platinum ⭐️⭐️⭐️
July 28, 2022

Hi ,

If you want to extract the value (3032) of the name "roll no" into flowfile attribute called "roll no" you can accomplish this with two processors as follows:

 

1- EvaluateJsonPath:

    roll no = $.[?(@.name=='roll no')].value

    Make sure the Return Type is set to Json since the exrepssion above will return json ["3032"].

 

SAMSAL_0-1659035286850.png

 

2- Update Attribute : which will extract the actual value from result json above with the following  attribute:   roll no = ${'roll no':jsonPath('$[0]')}

 

SAMSAL_1-1659035395931.png

 

Also you can refer to :

https://community.cloudera.com/t5/Support-Questions/Unable-to-return-a-scalar-value-for-the-expression-from-NIFI/td-p/213677

 

If that helps, please Accept Solution. Thanks

Translate
divnid
divnidAuthor
Silver ⭐️
July 29, 2022

It worked for me. Thanks.

 

Translate