0
votes

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?

2
Would you please post your EvaluateJsonPath configuration?Behrouz Seyedi
I tried "EvaluateJsonPath" ,but it is mainly used when we pull a json file from certain location right? before that I am trying the splitjson processor, I am getting invalid json format error.. but my goal is to extract json data from Post Request(the json data is already available in queue).praveen sangalad
For debugging my Json, i saved my "test files" on a repository with PutFile processor. Especially for Json, I used this tool to help me!BastienB
I used Postman instead of CURL command,I was able to retrieve the required fieldspraveen sangalad

2 Answers

1
votes

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
1
votes

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