Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON parse error: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null');

Requirement is to consume a webservice and persist in database. I wrote a stand alone class with Resttemplate and it works. I used same url and same authentication mechanism + spring boot, war deployed on tomcat then when I hit the endpoint(which calls the webservice to get json output) it throws exception.

There was an unexpected error (type=Bad Request, status=400).

JSON parse error: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null'); nested exception is com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [Source: java.io.PushbackInputStream@4be06322; line: 1, column: 2]

Can someone please assist.

Thanks.

like image 582
user7220859 Avatar asked May 04 '26 11:05

user7220859


1 Answers

I've had this error many times, and it turns out that I return HTML instead of JSON (hence the < character error).

To fix it, you need to check if the response is JSON or HTML to avoid parsing errors.

like image 164
Viradex Avatar answered May 06 '26 03:05

Viradex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!