Deserialize json showing error

Hi Community,
When i am using deserialize json activities it is throwing error
“Deserialize JSON: After parsing a value an unexpected character was encountered: t. Path ‘raw_response’, line 3, position 1.” but when i rerun the same, this error will gone and working fine and also sometimes it comes “object reference not set to an instance” also coming when i deserialize json but again when i rerun the same it will work, what is the reason for this unexpected behaviour for this?
Please help me to find the solution

Hi @alan.prakash ,

below might be the potential reasons of the behaviour

  • Inconsistent JSON Structure:
    Ensure that the JSON string you are trying to deserialize is well-formed and consistent every time it is fetched. Sometimes, the data source might return malformed JSON or unexpected characters, causing the deserialization to fail.
  • Race Conditions or Timing Issues:
    If your workflow fetches the JSON data from an external source (like a web service) and deserializes it immediately, there might be timing issues or race conditions. Adding a short delay before deserialization can sometimes help.
  • Handling Null or Empty Responses:
    If the JSON data you are deserializing is sometimes null or empty, this can cause the “object reference not set to an instance” error. Ensure that you check if the JSON string is not null or empty before attempting to deserialize it.

@alan.prakash

  • **Error: “After parsing a value an unexpected character was encountered: t. Path ‘raw_response’, line 3, position 1.”**This error typically occurs when the JSON string is not well-formed. It means that the JSON parser encountered an unexpected character while trying to parse the JSON string. The fact that it sometimes works and sometimes doesn’t suggests that the input JSON string might be changing or getting corrupted intermittently.
  • **Error: “Object reference not set to an instance of an object.”**This error usually occurs when you try to access an object that is null or not initialized. This might be happening if the JSON string is empty or null.

this json fetching from the api and api data not showing any null value i have checked it but still showing object reference not set to an instance of object but again when i rerun after sometime this error will go same with unexpected character error , i have given little delay but still results are like this , is this because of json data fetched from API?

yes the iisues u are facing is all due to json data . what is the response code u are getting after hittingg the api?

Response i am getting is 200 but sometimes only this issues coming

Hi @alan.prakash

Try below approach

  1. Print the jsonResponse and confirm that the API is consistently returning valid JSON. Reach out to the API provider if you suspect any changes in the response structure.

  1. Implement a check to verify whether the response is returning any value before attempting to deserialize it.

  1. Place this logic in a Retry Scope to avoid any errors related to network issues or API calls.

Hope it helps!!
Happy Automation :uipath: