Post Closed
1909
Views
10
Comments
Solved
Error while parsing JSON Response in REST API Post call
Question

I am using Outsystems 10 and trying to consume a REST API (single method)


I have copied and pasted the REST Request and Response JSON definitions into the Request and Response text boxes provided by OS REST API. I used the "TEST" button to validate if it was working - I received a 200 OK message. When I closed the dialog - Oustystems automatically created the Request and Response objects.


When I invoke the same REST method through the UI, it is raising a parsing error.


I switched to returning a JSON String and then Deserialize the JSON String, it still raises an error "Failed to parse response of the method 'APIItemSearch' of the 'Enterprise' REST API:

Parsing '': Unexpected character encountered while parsing value: <. Path '', line 0, position 0."


Any ideas on how to resolve this issue?



REQUESTS OBJECT

{  

   "CountryCode":"US",

   "SearchString":"Ford Escape"

}


RESPONSE OBJECT

{  

   "Options":[  

      {  

         "Field1":0,

         "Field2":0,

      }

   ],

   "SearchStringUsed":"String",

   "CountriesFound":[  

      {  

         "Key":"String",

         "Description":"String",

         "Count":0

      }

   ],

   "ModelYearsFound":[  

      {  

         "Key":"String",

         "Description":"String",

         "Count":0

      }

   ],

   "MakesFound":[  

      {  

         "Key":"String",

         "Description":"String",

         "Count":0

      }

   ],

   "ModelsFound":[  

      {  

         "Key":"String",

         "Description":"String",

         "Count":0

      }

   ],

   "MatchedCriteria":"String",

   "NotMatchedCriteria":"String",

   "IsNotExactMatch":false,

   "ResponseStatus":{  

      "ErrorCode":"String",

      "Message":"String",

      "StackTrace":"String",

      "Errors":[  

         {  

            "ErrorCode":"String",

            "FieldName":"String",

            "Message":"String",

            "Meta":{  

               "String":"String"

            }

         }

      ],

      "Meta":{  

         "String":"String"

      }

   }

}


UserImage.jpg
Ravi Subbarao
Solution

Hi Kilian, Assif and Eduardo

I was able to resolve the issue. I had forgotten to append "?format=json" at the end of the REST url. So it was returning a HTML doc instead of a JSON object.

Regarding the "," in the JSON - I had edited the Correct JSON  to simplify  the number of  fields  (50).

I want to thank you all for helping me - I appreciate your help.

Thank you.

2021-04-09 11-42-43
assif_tiger
 
MVP

Ravi Subbarao wrote:

Hi Kilian, Assif and Eduardo

I was able to resolve the issue. I had forgotten to append "?format=json" at the end of the REST url. So it was returning a HTML doc instead of a JSON object.

Regarding the "," in the JSON - I had edited the Correct JSON  to simplify  the number of  fields  (50).

I want to thank you all for helping me - I appreciate your help.

Thank you.

Happy to know... You Resolve :)

Keep Coding..

Cheers,

Assif

UserImage.jpg
Aron Yang

Ravi Subbarao wrote:

Hi Kilian, Assif and Eduardo

I was able to resolve the issue. I had forgotten to append "?format=json" at the end of the REST url. So it was returning a HTML doc instead of a JSON object.

Regarding the "," in the JSON - I had edited the Correct JSON  to simplify  the number of  fields  (50).

I want to thank you all for helping me - I appreciate your help.

Thank you.


Hi Ravi Subbarao

I also have the same error when consuming rest API. But I can not use your way to solve my problem.

Is there another way to check row json data if I fetch data from other Sources? 


Thanks

2019-10-04 15-01-22
Dhiraj Manwani

Aron Yang wrote:

Ravi Subbarao wrote:

Hi Kilian, Assif and Eduardo

I was able to resolve the issue. I had forgotten to append "?format=json" at the end of the REST url. So it was returning a HTML doc instead of a JSON object.

Regarding the "," in the JSON - I had edited the Correct JSON  to simplify  the number of  fields  (50).

I want to thank you all for helping me - I appreciate your help.

Thank you.


Hi Ravi Subbarao

I also have the same error when consuming rest API. But I can not use your way to solve my problem.

Is there another way to check row json data if I fetch data from other Sources? 


Thanks


Hi Aron,


Can you share you JSON data?

both req and response would be much helpful.

UserImage.jpg
Aron Yang

Dhiraj Manwani wrote:

Aron Yang wrote:

Ravi Subbarao wrote:

Hi Kilian, Assif and Eduardo

I was able to resolve the issue. I had forgotten to append "?format=json" at the end of the REST url. So it was returning a HTML doc instead of a JSON object.

Regarding the "," in the JSON - I had edited the Correct JSON  to simplify  the number of  fields  (50).

I want to thank you all for helping me - I appreciate your help.

Thank you.


Hi Ravi Subbarao

I also have the same error when consuming rest API. But I can not use your way to solve my problem.

Is there another way to check row json data if I fetch data from other Sources? 


Thanks


Hi Aron,


Can you share you JSON data?

both req and response would be much helpful.


Hi Dhiraj Manwani


I add another new post for more detail information including json data. https://www.outsystems.com/forums/discussion/53361/parsing-error-when-consuming-rest-api-on-mobile-app/#Post199737

Could you help to take a look?

Thanks

BR,

Aron

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Ravi,

Very likely you are getting a HTML error page as response, given that the complaint is about a "<" at the very first position. I would like to suggest to turn on the debug logging for your REST service, and check in Service Center what's really sent and received.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

I think the only problem is the comma after "Field2:0", not sure what else would be wrong. But as I already said, the error indicates something else alltogether, so my advise stands.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Sorry, but I see commas everywhere? My go-to validator is here, and it shows only that one error I already spotted with my bare eye.

2021-04-09 11-42-43
assif_tiger
 
MVP

Hi Ravi Subbarao,

The Entire JSON will be  Valid If you only correct additional comma.

Ref: https://codebeautify.org/jsonvalidator

Hope it helps,

Assif


2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

It seems Assif agrees with me, Eduardo :).

However, again, that has nothing to do with Ravi's original question, as that syntax error in the JSON will be picked up by Service Studio, so I'm sure Ravi just copy/pasted parts of a larger JSON. In the error message, it clearly states there a "<" in the respons at the first position, and that's very common in case there's some error that makes the web server send an HTML error page instead of JSON.

UserImage.jpg
Ravi Subbarao
Solution

Hi Kilian, Assif and Eduardo

I was able to resolve the issue. I had forgotten to append "?format=json" at the end of the REST url. So it was returning a HTML doc instead of a JSON object.

Regarding the "," in the JSON - I had edited the Correct JSON  to simplify  the number of  fields  (50).

I want to thank you all for helping me - I appreciate your help.

Thank you.

2021-04-09 11-42-43
assif_tiger
 
MVP

Ravi Subbarao wrote:

Hi Kilian, Assif and Eduardo

I was able to resolve the issue. I had forgotten to append "?format=json" at the end of the REST url. So it was returning a HTML doc instead of a JSON object.

Regarding the "," in the JSON - I had edited the Correct JSON  to simplify  the number of  fields  (50).

I want to thank you all for helping me - I appreciate your help.

Thank you.

Happy to know... You Resolve :)

Keep Coding..

Cheers,

Assif

UserImage.jpg
Aron Yang

Ravi Subbarao wrote:

Hi Kilian, Assif and Eduardo

I was able to resolve the issue. I had forgotten to append "?format=json" at the end of the REST url. So it was returning a HTML doc instead of a JSON object.

Regarding the "," in the JSON - I had edited the Correct JSON  to simplify  the number of  fields  (50).

I want to thank you all for helping me - I appreciate your help.

Thank you.


Hi Ravi Subbarao

I also have the same error when consuming rest API. But I can not use your way to solve my problem.

Is there another way to check row json data if I fetch data from other Sources? 


Thanks

2019-10-04 15-01-22
Dhiraj Manwani

Aron Yang wrote:

Ravi Subbarao wrote:

Hi Kilian, Assif and Eduardo

I was able to resolve the issue. I had forgotten to append "?format=json" at the end of the REST url. So it was returning a HTML doc instead of a JSON object.

Regarding the "," in the JSON - I had edited the Correct JSON  to simplify  the number of  fields  (50).

I want to thank you all for helping me - I appreciate your help.

Thank you.


Hi Ravi Subbarao

I also have the same error when consuming rest API. But I can not use your way to solve my problem.

Is there another way to check row json data if I fetch data from other Sources? 


Thanks


Hi Aron,


Can you share you JSON data?

both req and response would be much helpful.

UserImage.jpg
Aron Yang

Dhiraj Manwani wrote:

Aron Yang wrote:

Ravi Subbarao wrote:

Hi Kilian, Assif and Eduardo

I was able to resolve the issue. I had forgotten to append "?format=json" at the end of the REST url. So it was returning a HTML doc instead of a JSON object.

Regarding the "," in the JSON - I had edited the Correct JSON  to simplify  the number of  fields  (50).

I want to thank you all for helping me - I appreciate your help.

Thank you.


Hi Ravi Subbarao

I also have the same error when consuming rest API. But I can not use your way to solve my problem.

Is there another way to check row json data if I fetch data from other Sources? 


Thanks


Hi Aron,


Can you share you JSON data?

both req and response would be much helpful.


Hi Dhiraj Manwani


I add another new post for more detail information including json data. https://www.outsystems.com/forums/discussion/53361/parsing-error-when-consuming-rest-api-on-mobile-app/#Post199737

Could you help to take a look?

Thanks

BR,

Aron