Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Add flow attribute from Json

avatar
New Contributor

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

1 ACCEPTED SOLUTION

avatar

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-expressi...

 

If that helps, please Accept Solution. Thanks

View solution in original post

2 REPLIES 2

avatar

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-expressi...

 

If that helps, please Accept Solution. Thanks

avatar
New Contributor

It worked for me. Thanks.