JSON Diff
Compares two JSON documents and reports every added, removed and modified key or value, each with its path. Runs locally in Python's standard library. No credential, no network.
Tool ID
json-diff
Credential Required
No.
Use case
Catch drift between two versions of the same JSON: yesterday's API response against today's, a config file before and after a deploy, an export against its baseline. A later task can branch on hasChanges or send summary as an alert.
Published Outputs
| Output | Description |
|---|---|
hasChanges |
"true" or "false" |
changeCount |
Total number of differences |
summary |
One sentence, e.g. Found 4 difference(s): 2 added, 1 removed, 1 modified. |
added |
JSON array of {path, key or index, value} present only in modified |
removed |
JSON array of {path, key or index, value} present only in original |
modified |
JSON array of {path, oldValue, newValue} |
diff |
Everything above as one JSON object |
Example
Input:
{
"tool": "json-diff",
"properties": {
"original": "{\"name\": \"widget\", \"price\": 10, \"tags\": [\"a\", \"b\"], \"stock\": {\"nyc\": 4, \"sfo\": 2}}",
"modified": "{\"name\": \"widget\", \"price\": 12, \"tags\": [\"a\", \"b\", \"c\"], \"stock\": {\"nyc\": 4}, \"sku\": \"W-1\"}"
}
}
Actual captured output:
summary Found 4 difference(s): 2 added, 1 removed, 1 modified.
hasChanges true
changeCount 4
added [{"path": "sku", "key": "sku", "value": "W-1"}, {"path": "tags[2]", "index": 2, "value": "c"}]
removed [{"path": "stock.sfo", "key": "sfo", "value": 2}]
modified [{"path": "price", "oldValue": 10, "newValue": 12}]
How it works
Objects are compared key by key and the comparison recurses into nested objects, so a change deep in the document is reported at its full path (stock.sfo). Arrays are compared position by position.
Each input may be JSON text or the path of a .json file readable by the InTouch server.
Chaining Patterns
- http → json-diff → message — alert when an API response differs from a saved baseline
- file → json-diff — compare a config file before and after a change
- Use
{{task.hasChanges}}in a later task'sifto act only when something changed
Limitations
- Arrays are compared by position. Inserting an element at the front of an array reports every later element as modified rather than as one insertion.
- An input that is not valid JSON does not fail the task:
summarycarries the parse error andhasChangesis"false". Checksummaryif a "no changes" result is surprising. - Values are compared exactly:
1and1.0are equal,"1"and1are not.
Source
tool.iml, json_diff.py
Publishes
The keys a later task may reference as {{taskName.key}}. Referencing anything not listed here resolves to nothing at run time.
addedchangeCountdiffhasChangesmodifiedremovedsummary
Input Properties
Every property this tool accepts, from its own tool.iml.
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
original |
string | yes | — | The first (original) JSON document: JSON text, or the path of a .json file on the server. |
modified |
string | yes | — | The second (modified) JSON document: JSON text, or the path of a .json file on the server. |