diff method

DiffNode diff()

Compare the two JSON Strings, producing a DiffNode.

The differ will walk the entire object graph of each JSON object, tracking all additions, deletions, and changes. Please see the documentation for DiffNode to understand how to access the differences found between the two JSON Strings.

Implementation

DiffNode diff() {
  if (leftJson is Map && rightJson is Map) {
    return _diffObjects(
      (leftJson as Map).cast<String, Object?>(),
      (rightJson as Map).cast<String, Object?>(),
      [],
    )..prune();
  } else if (leftJson is List && rightJson is List) {
    return _diffLists((leftJson as List).cast<Object?>(),
        (rightJson as List).cast<Object?>(), null, []);
  }
  return DiffNode([])..changed[''] = [leftJson, rightJson];
}