This utility module returns calculates the difference between two values and returns the list of differences

Functions

diff

diff(Any, Any, { unordered?: Boolean }, String): Diff

Returns the structural diference between two values. It returns an Difference. When comparing objects it can be either ordered or unordered. By default is ordered this means that two object are not going to have a difference if their key value pairs are in the same order. To change this behaviour specify the diffConfig parameter with {unordered: true}

Example:
1
2
3
4
5
6
7
%dw 2.0
import * from dw::util::Diff
output application/json
var a = { age: "Test" }
var b = { age: "Test2" }
---
 a diff b
Output:
1
2
3
4
5
6
7
8
9
10
{
"matches": false,
 "diffs": [
   {
     "expected": "\"Test2\"",
     "actual": "\"Test\"",
     "path": "(root).age"
   }
 ]
}

Types

Diff

Describes the entire difference beteween two values

Definition
1
{ matches: Boolean, diffs: Array<Difference> }

Difference

Describes a single difference between two values at a given structure

Definition
1
{ expected: String, actual: String, path: String }