praveen sangalad
praveen sangalad

Reputation: 338

Not able to extract Json Data in Apache-NiFi

I have written a below POST command and using "HandleHttpRequest" processor to receive the POST request in Apache NiFi

curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"employeeDetails":{"empid":"124","empname": "praveen"}}' http://localhost:7002

I am able to receive the json data in "handleHttpRequest" processor as shown below

enter image description here

when I check the list queue I am able to see the json data

enter image description here

HandleHttpProcessor details

enter image description here

But I want to extract empid and check whether empid of my json data is null or not,I tried "ExtractText","ReplaceText","UpdateAttribute","EvaluateJsonPath" etc Processors to fetch empolyee details but I am unable to do it.

EvaluateJson path details

enter image description here

I am getting "flowfile did not have a valid JSON content" error in EvaluateJsonPath processor

How do I extract empdata and check whether its null or not?

Upvotes: 0

Views: 1745

Answers (2)

sandhya raghavan
sandhya raghavan

Reputation: 21

I have the exact same two processors you have, additionally, I also have a HandleHTTPResponse added so that my curl command exits neatly without sending additional buffer messages that make the EvaluateJSONPath component fail with invalid JSON error (My guess is this could have been your case as well). HTTP Request Flow

Also as @Behrouz Seyedi mentioned you would need to use a single quote in your command. This is my curl command

curl -v -H "Content-type: application/json" -X POST -d '{"employeeDetails":{"empid":"124","empname": "praveen"}}' http://localhost:7003

This is the screenshot to the EvaluateJSONPath processor.

This is the response of the EvaluateJSONPath empid

Upvotes: 1

Behrouz Seyedi
Behrouz Seyedi

Reputation: 316

The problem is not related to NiFi. You should post data with CURL like this (change double quote " to single quote ' after -d):

curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"employeeDetails":{"empid":"124","empname": "praveen"}}' http://localhost:7002

Upvotes: 1

Related Questions