JObject error - Object reference not set to an instance of an object

Hello, I get a null object error. Basically, I make an API call (HTTP) request. I get the response data (JSON string) and store it in a string variable. I then use a Deserialize activity to convert the JSON string to a JObject. However, when I try to extract data from the JObject variable, I get a null object error. To make matters even more weird, the JObject shows that it has a value populated with data when I view it in the local variables watch pane when running in debug mode. For context, earlier in my workflow, I am deserializing response data from a previous HTTP request and assigning it to a JObject as well and I have no problem extracting data from that JObject variable. But after getting response data from the 2nd HTTP request, I am having this null object problem. I have attached a screenshots of the variables debugging watch pane which shows that the JObject has a value. Can anyone help?

So we would assume that the extraction / access is failing, as the JObject is not null.

Maybe you can share with us the JSON as a text file along with the description of what is to extract

Hey PPR, I found out what the problem was. The JObject did have a value but the reason I was getting a null error was because I was using the wrong expression to extract the specific property (sys_ID) within the JObject. The correct expression to reference the JObject property is JObjectVariable.SelectToken(“result”)(“PropertyName”).ToString. So, replace JObjectVariable with the name of your JObject variable and replace PropertName with the specific property whose value you want to obtain. However, there are other times when you can simply use the following expression to obtain a JObject property value

JObjectVariable(“PropertyName”).ToString

So, I am unsure when it is ok to use the 2nd expression and when you need to use the first expression. Just to be on the safe side, we should probably just use first expression and that should always work. However, in the unlikely event it does not work, then the 2nd expression should work for sure.

But yeah, that was the problem

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