the diff for arrays does not reference array indexes
srinivasj-sys opened this issue · 3 comments
the resultant json-patch document after comparing two JSONs does not have the right patch operations for arrays based on indexes.
the json-patch for an array should look like this
{
"op": "replace",
"path": "/options/1/value",
"value": "soln-v1 1"
},
{
"op": "replace",
"path": "/options/1/label",
"value": "item 1_1"
},
{
"op": "add",
"path": "/options/2",
"value": {
"label": "item 1_2",
"value": "soln-v1 2"
}
}
I have an array containing in the source JSON
{"options": [ {"label": "item 1", "value": "item 1"},{"label": "item 2", "value": "item 2"}]}
and an modified array in the target JSON
{"options": [ {"label": "item 1", "value": "item 1"},{"label": "item 1_1", "value": "soln-v1 1"},{"label": "item 1_2", "value": "soln-v1 2"}]}
the output should look like the example provided
and not a replace of the entire source array to the target array.
HTH.
NOTE: This is for the CompareJSON() method. The Compare() method works very well.
Thanks and Regards,
Srinivas
@srinivasj-sys
Did you use any of the options ? You say that it generate an entire replace of the array, rather than three operations. The Rationalize
option does exactly that.
I can't reproduce your example, see https://goplay.tools/snippet/DGjvdLRrQ6U. This generates three operations with the CompareJSON
method, for the inputs you provided.
ahh.. no options does the right thing. I did use the Factorize() and Rationalize() options.
@srinivasj-sys
See the README.md for an explanation on the options behaviour.