Skip to content

How do I compare two different JSONs

This example demonstrates comparing two different JSONs.

In the solution shown below, the two JSON objects are stored into the variables using "store" command and compared using "jsonCompare" command. The result is stored into a variable. The command returns "1" if the JSONs are similar, else it returns "0".

Note: The notation to reuse the value of the variable in Worksoft SaaS is ${<Variable Name>}.

Solution:

# Command Target Value
Store the JSON object 1 in a variable
1 store {"zipcodeDetails":[{"zipcode":90001,"state": "California"},{"zipcode":10001,"state": "New York"}]} JSON_1
Store the JSON object 2 in a variable
2 store
{"zipcodeDetails":[{"zipcode":90001,"state": "California"},{"zipcode":10001,"state": "New York"}]}
JSON_2
Compare the JSON objects and store the result in a variable
3 jsonCompare
${JSON_1} || ${JSON_2}
JSON_Comparision

Tips, Tricks, Gotchas & Best Practices:  

  • You can also call both the JSON objects directly in the "Target" field separated by "||" symbol in "jsonCompare" command instead of storing them into a variable.
  • As a best practice, it is always advisable to define the variable names without any spaces and if you want to differentiate the words, use underscores.


Feedback and Knowledge Base