Support Questions

Find answers, ask questions, and share your expertise

How to extract json array using EvaluateJsonPath processor in NiFi?

avatar
Rising Star

Hi,

I have json flowfile,  [{"prediction":"Test2"},{"prediction":"Test2"}].

 

I am want extract the 1st part of the array ie prediction":"Test2  my destination is flowfile-attribute using EvaluateJsonPath .

 

I have added a custom attribute mlresult --->$.prediction[0], to extract the "Test2" into mlresult, but I am getting empty string  for the mlresults for the flow file attribute section.

 

flow file : [{"prediction":"Test2"},{"prediction":"Test2"}]

EvaluateJsonPath configuration:

 

mlresult.PNG

 
 

 

 

How to get the value(only one)  Test2 to mlresult?

 

Thanks

--Murali

 

 

 

1 ACCEPTED SOLUTION

avatar
Master Collaborator

@murali2425 

Here are two possible solutions.

2021-03-01_HCC_json.png


At solution 1 the value is set into an array.

At solution 2 I took the flowfile-content (json) and set it into an attribute. Then you can work with expression language to get the value.


For testing the syntax I recommend this site:
http://jsonpath.herokuapp.com/

View solution in original post

1 REPLY 1

avatar
Master Collaborator

@murali2425 

Here are two possible solutions.

2021-03-01_HCC_json.png


At solution 1 the value is set into an array.

At solution 2 I took the flowfile-content (json) and set it into an attribute. Then you can work with expression language to get the value.


For testing the syntax I recommend this site:
http://jsonpath.herokuapp.com/