Support Questions

Find answers, ask questions, and share your expertise

Nifi - Getting JSON parse exception while making a curl call to rest api

avatar
Contributor

I am using execute stream command processor to make a curl call to rest api and getting below json parse exception.

 

curl.PNG

 

Curl Call: (below command was extracted into a variable called curlcommand as mentioned in the screenshot)

--location;--request;POST;"https://abc.com/data";--header;${content_type};-d;"[{"bin": "02608","groupId": "52821094"},{"bin": "02609","groupId": "528212387"}]"

 

Exception: 

{"timestamp":1580154052402,"status":400,"error":"Bad Request","message":"JSON parse error: Unexpected character ('b' (code 98)): was expecting double-quote to start field name; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Unexpected character ('b' (code 98)): was expecting double-quote to start field name\n at [Source: (PushbackInputStream); line: 1, column: 2] (through reference chain: java.util.ArrayList[0])","path":"/data"}

 

Please help..

7 REPLIES 7

avatar
Master Mentor

@VijaySankar 

What is your NiFi Version?

 

Looks like there is already a similar JIRA [1]  Which seems to be addressing this behaviour of "ExecuteStreamCommand" in the NiFi version "1.10.0".


[1] ExecuteStreamCommand filters out any double quotes when parsing the "Command Arguments"

     https://issues.apache.org/jira/browse/NIFI-3221

avatar
Contributor

@jsensharma Thanks for your response.

We are using 1.7.

I changed ExecuteStreamCommand to InvokeHTTP processor.

avatar
Super Guru

Escape the "s in the json data object:

 

"[{\"bin\": \"02608\",\"groupId\": \"52821094\"},{\"bin\": \"02609\",\"groupId\": \"528212387\"}]"

 

Let us know if this works, and if it does please accept this answer.

avatar
Contributor

Thanks @stevenmatison.

I tried escape "s and still it is failing.

avatar
Super Guru

@VijaySankar  did you get it solved? 

avatar
Explorer

NO! 

avatar
Explorer

If double quotes are escaped, then the processor does not remove them, but the command is also sent with a backslash before the double quotes. does not work.