Not Able to read json data

Hi All, I am trying to read json response received from HTTP Request activity. I am using for each loop to get data after deserialize the data and store it to JObject Variable. After executing I am getting error "For Each: Object reference not set to an instance of an object. I am pasting Json Body as below in which I am trying to fetch all data within “RPAVcatEntitiesList”.

{
“Service”: {
“ServiceHeader”: {
“StatusMsg”: “Success”,
“StatusCode”: “200”
},
“ServiceBody”: {
“CallResponse”: {
“RPAVcatEntitiesList”: [
{
“SerialNumber”: “”,
“CustomerGivenHostName”: “”,
“IMSI”: “222233334444”,
“CircuitID”: “”,
“IMEI”: “222233334444”,
“SIM_ICCID”: “”,
“CaseID”: “CR-2855”,
“CustomerName”: “E2E-USA-15372-DEAPEGA”,
“DNSName”: “deapega-test1-3072095e001”,
“TransactionID”: “b8effb6a-4f51-4g00-a788-7de1e476746a”
}
]
}
}
}
}

@shekharhimanshu627, this error means your JObject Variable is null. Check if you have passed this variable to output property of Deserialize JSON activity.

Share the workflow if possible.

Thanks,
Ashok :slight_smile:

@ashokkarale Thanks For your response.
Main (3).xaml (22.6 KB)

Please find the attached workflow that I am using. I tried in both way a) Passing Variable and b) Reading text file.

Hi @shekharhimanshu627

Check the below workflow:
FLOW:

XAML:
Sequence2.xaml (15.9 KB)

OUTPUT:
image

Let me know if you have any issues
Hope it helps!!

Hi @shekharhimanshu627 ,

  • Null Reference: Ensure the JSON structure matches the provided example and the keys are correctly referenced.
  • Type Argument: Set the “Type Argument” of the “For Each” loop to JToken to correctly handle the items in the JSON array.
  • Empty Array: If the JSON array is empty, ensure your workflow can handle this scenario gracefully.

To address the error “For Each: Object reference not set to an instance of an object” in UiPath, ensure that the JSON structure is correctly parsed and that the “RPAVcatEntitiesList” array is correctly accessed. Below is a step-by-step solution to parse the given JSON response and iterate through the “RPAVcatEntitiesList” array:

  1. Assign JSON Response: Ensure that you have assigned the JSON response to a string variable (e.g., jsonResponse).
  2. Deserialize JSON: Use the “Deserialize JSON” activity to convert the JSON string into a JObject variable (e.g., jObject).
  3. Extract Data: Use a “For Each” loop to iterate through the “RPAVcatEntitiesList” array within the JObject.

Regards
Sandy

@shekharhimanshu627,

Here you go.

  1. Deserialize the JSON to JSON Object
  2. Desterilize the JSON Object Key GetResponse_Output("Service")("ServiceBody")("CallResponse")("RPAVcatEntitiesList").ToString() To JSON Array.
  3. Now Iterate the JSON Array using For Each.

Output:
image

Updated Workflow:
Main (3).xaml (24.4 KB)

Thanks,
Ashok :slight_smile:

Hi @ashokkarale,

Provided Solution is working as expected. Thanks

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.