Compare a JSON with Another JSON
Compares two JSON objects and identifies differences between them.
Overview
This procedure compares two JSON objects and identifies the differences between them. It returns a list of keys where the values differ between the two objects, including keys that exist in one object but not the other. The comparison is performed at the top level of the JSON objects.
Input
target
json
The first JSON object to be compared
Yes
N/A
object
json
The second JSON object to be compared
Yes
N/A
Output
differences
A list of keys where the values differ between the two JSON objects. Each difference is represented as a string indicating the key that differs
Examples
1. Comparing simple JSON objects with one difference
This example compares two JSON objects and identifies that the "age" field differs.
set the target to
{
"name": "John",
"age": 30,
"city": "New York"
}
set the object to
{
"name": "John",
"age": 31,
"city": "New York"
}
compare the target json with the object json2. Comparing nested JSON objects
This example compares two JSON objects with nested structures. Note that the comparison identifies "specs" as different (since the nested object differs), not the individual nested fields.
set the target to
{
"product": "Laptop",
"price": 1200,
"specs": {
"RAM": "16GB",
"Storage": "512GB SSD"
}
}
set the object to
{
"product": "Laptop",
"price": 1200,
"specs": {
"RAM": "8GB",
"Storage": "256GB SSD"
}
}
compare the target json with the object json3. Complete comparison workflow with result handling
This example demonstrates a complete workflow: loading two JSON objects (where the actual json might be {"name": "john", "age": 28} and expected json is {"name": "john", "age": 29}), comparing them, and storing the list of differences (["age"]) in a fact for later use.
get the actual json
get the actual json as a json
the actual json is a json
get the expected json
get the expected json as a json
the expected json is a json
compare the expected json with the actual json
use the above as the keys
the keysLast updated
Was this helpful?
