Here it is having object inside object. I just want to compare the data.
Hi @companir
- You can use the “Deserialize JSON” activity to convert the JSON objects into dynamic variables or objects.
- Provide the JSON string or file as input to the activity.
- Assign the output to two variables, let’s say “jsonObj1” and “jsonObj2”.
-
Initialize an empty list variable, let’s call it differences, to store the differences between the JSON objects.
-
Use a For Each activity to iterate through the properties/keys of jsonObj1. Choose the appropriate iterator type based on the data structure of the JSON object (e.g., Dictionary or JObject).
-
Inside the For Each loop, check if the current property/key exists in jsonObj2 using an If activity.
-
If the property/key exists in jsonObj2, compare the corresponding values of both JSON objects using an If activity.
- Convert the values to strings for comparison (if necessary) using the ToString method.
- If the values are different, add the property/key, value from jsonObj1, and value from jsonObj2 to the differences list.
- After the For Each loop completes, you can display or process the differences list as per your requirements.
Hope that helps
But here the JSON is having object inside an object format, right? How do you iterate in such case?
@companir
Use a For Each activity to iterate through the properties/keys of jsonObj1 using the Get JToken activity.
Set the Token field to jsonObj1.
Set the TypeArgument to Newtonsoft.Json.Linq.JProperty.
Inside the For Each loop, check if the current property/key exists in jsonObj2 using the JToken.HasValues method.
- Use an If activity with the condition jsonObj2.HasValues(Of Newtonsoft.Json.Linq.JProperty)(Function(x) x.Name = item.Name).
If the property/key exists in jsonObj2, compare the values of both JSON objects using an If activity.
- Use an If activity with the condition Not JToken.DeepEquals(jsonObj1(item.Name), jsonObj2(item.Name)).
This is a little bit complicated. Alternatively you could also write custom Code and invoke it.
further information on getting specif values here: Nested JSON Deserialization and get specific values
Which package has Get JToken Activity? Didn’t find anything on internet.
Hi @companir you don’t need an extra Package except UiPath.WebAPI.Activities. A possible solution is descirbed here: Need to extract multiple data from JSON - #2 by ppr