Support Questions
Find answers, ask questions, and share your expertise

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

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

Explorer

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

5 REPLIES 5

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

Super 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

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

Explorer

@jsensharma Thanks for your response.

We are using 1.7.

I changed ExecuteStreamCommand to InvokeHTTP processor.

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

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.

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

Explorer

Thanks @stevenmatison.

I tried escape "s and still it is failing.

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

@VijaySankar  did you get it solved?