Json Diff
AI-generatedOverview
The Json Diff node compares two JSON objects or arrays and outputs their differences. It is useful in scenarios where you need to identify changes between two versions of data, such as:
- Detecting updates in API responses.
- Comparing database records before and after an operation.
- Auditing configuration changes.
Practical examples:
- Compare two user profile objects to see what fields have changed.
- Check for added, removed, or modified items in a list of products.
Properties
| Name | Type | Meaning |
|---|---|---|
| Json A | String | The first JSON object to compare. |
| Json B | String | The second JSON object to compare. |
| Check Specific Array | Boolean | Whether to compare specific arrays within the JSON objects instead of the whole objects. |
| Array to Check | String | (Shown if "Check Specific Array" is true) The property name of the array to compare. |
| ID Field | String | (Shown if "Check Specific Array" is true) The field used as a unique identifier in array comparison. |
Output
If comparing entire objects:
- Each output item contains a
jsonfield with adiffproperty showing the difference between the two JSON objects, using the json-diff format.
{ "diff": [ ["~", "fieldName", "oldValue", "newValue"], ["+", { /* new object */ }], ["-", { /* removed object */ }] ] }- Each output item contains a
If comparing arrays:
- Each output item contains a
jsonfield with:id: The value from the specified ID Field.diffType: The type of difference (+for addition,-for removal,~for modification).diff: The actual diff content for that array element.
{ "id": "123", "diffType": "~", "diff": [/* diff details */] }- Each output item contains a
If an error occurs and "Continue On Fail" is enabled, the output will include an
errorfield with error details.
Dependencies
External Libraries:
n8n Configuration:
- No special environment variables or credentials are required.
Troubleshooting
Common Issues:
- Invalid JSON Input: If either "Json A" or "Json B" is not valid JSON, the node attempts to use the raw input but may produce unexpected results.
- Missing Array or ID Field: When "Check Specific Array" is enabled, ensure both "Array to Check" and "ID Field" are correctly set and exist in both JSON inputs.
- No Array Found: If the specified array does not exist in either input, the node throws a "no Array found" error.
Error Messages:
"no Array found": The specified array property was not found in one or both JSON inputs. Double-check the "Array to Check" property.- JSON parsing errors: Ensure your "Json A" and "Json B" inputs are valid JSON strings.