jsondiffpatch icon indicating copy to clipboard operation
jsondiffpatch copied to clipboard

Diff of identical objects with nested arrays causes invalid diff when there should be none

Open ted-kramer opened this issue 9 months ago • 1 comments

let testValueA = {
   A: [
       ["B"],
       1,
       "C",
       2,
      "C"
   ]
}
let testValueB = structuredClone(testValueA);
let delta = jsondiffpatch.diff(testValueA, testValueB);

delta should be undefined but instead its:

{
  "A": {
    "0": [
      [
        "B"
      ]
    ],
    "_t": "a",
    "_0": [
      [
        "B"
      ],
      0,
      0
    ]
  }
}

It appears that this structure is somehow tripping up the diff algorithm. Stumbled on this randomly when some deeply nested config files happened to cause this to occur. I tried the array config options and neither made any difference in output.

ted-kramer avatar Apr 01 '25 21:04 ted-kramer

@ted-kramer have you tried using objectHash (see IMPORTANT NOTE on the readme)? if you did please add an example using one that can help match ["B"] with ["B"].

benjamine avatar Apr 01 '25 22:04 benjamine