Json Error in Output

Hi All,

I am trying to deserialiaze the Json data but getting an error

Deserialize JSON: Deserialized JSON type ‘Newtonsoft.Json.Linq.JArray’ is not compatible with expected type ‘Newtonsoft.Json.Linq.JObject’. Path ‘’, line 1, position 75.


Hi @marina.dutta

Can Use the below syntax
syntax : Newtonsoft.json.jsonconvert.deserializeobject(of datatable)(jsonstring)
Cheers!

Note the difference between a jsonobject and a jsonarray.
For comparison: a string and a string[ ] are not the same. Here you have a similar problem.

If your http requests requires a jobject as input, but your data is in the form of a jarray either:

  • loop through each item of the jarray using a for each
  • if your jarray only contains one item refer to it simply by using MyJsonArray(0) instead of MyJsonArray

@Dinesh_Guptil

Do I need to use assign activity and put the Json string something like this.

Yes the variable data type is datatable

@Dinesh_Guptil

I dont have to use the below activity then, just assign activity only for deseriliazation?

Yes use only assign font use deserialize json activity

@Jeroen_van_Loon

Can you show an example. here my quoteResponseData_source is the output of http request which I am trying to deseriliaze it.

quoteResponseData_source

@Dinesh_Guptil

But I am getting error in further activities when I am trying to use use those values to replace the json body with the values obtained. I am trying to use those values obtained from assign activity in replacing the values in Json template .getting an error as jsonQuoteBody is of type
String

@marina.dutta
Can you share the input data and your expected output

UC007_QA_Automation_QUOTE.zip (1.4 MB)

Hi @marina.dutta ,

Could you let us know if this error happens only when the INVALID SESSION error occurs ?

Form the Logs we could see that there are two types of outputs - Json Object and Json Array.

Is the error happening only at some times ?

@supermanPunch

Yes the error happens sometimes when and also the request Time out error happens even though I increased the Timeout

@marina.dutta ,

In that case, maybe we could first check whether the output received is a Json Object and if it contains the Key “access_token” and then perform the Deserialization and next steps. If it is not a Json, we can simply throw an Error stating it was not recognised as a Json or Session Expiry has occurred.

For Json Type Check, we can do the below :

JToken.Parse(JarrOrJObj_Text).Type.Equals(JTokenType.Object) AndAlso JsonConvert.DeserializeObject(Of JObject)(JarrOrJObj_Text).ContainsKey("access_token")

image

For JArray, it would give False Output :
image

Also Note, Newtonsoft.Json.Linq was also imported for this :
image

@supermanPunch

Thanks .let me implement that in my code

1 Like

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