Monday, May 22, 2017

JSON Decoder : Unexpected character encountered while parsing value

After fixing an error with JSON decoder -Property not specified in JSON decoder, got one more error from JSON decoder-

 Unexpected character encountered while parsing value

Unexpected character encountered while parsing value <

From the error it is clear that the data in response from the api is not valid JSON, thus the decoder throws error.

Why it happened

I went through the tracked service instance and checked what exactly is received, and as can be seen in below snap - it was HTML and no JSON message. 

response html message

And as the returned message starts with <  , the decoder was not able to parse it as valid JSON message is like:

   "company": "Maruti",
   "name": "Swift",
   "price": 800000

Note: The RestApi has not implemented the required functionality, only instance of webapi is provisioned in Azure - thus the HTML is returned.

What to do 

Here, we can't do anything except get the functionality implemented in Rest Api and let it return valid message. This error can also be encountered in case you are using JSON decoder and you receive XML.


  1. I think you are getting a JSON object (an array of JSON message which is enclosed in []) as input, so JSON decoder will not support JSON array. You have to write a custom pipline component to convert it to a valid xml.

  2. Hi Srikanth,

    Here I am getting HTML, so there was error.

    Thanks for comment ... will check for JSON array too