JSON8
JSON8 copied to clipboard
Objects with arrays that change create wordy patches
I noticed that json8-patch seems to be quite fast, with the exception of arrays. Consider the following:
var obj = {
"x": "SomeVal",
"y": [{ "z": 2}, {"z": 3}, {"z": 4}, {"z": 5}]
}
var obj2 = {
"x": "SomeVal",
"y": [{ "z": 2}, {"z": 6}, {"z": 4}, {"z": 5}]
}
I would expect this to return a patch of:
[
{
"op": "replace",
"path": "/y/1/z",
"value": 6
}
]
Instead, it returns:
[
{
"op": "replace",
"path": "/y",
"value": [
{
"z": 2
},
{
"z": 6
},
{
"z": 4
},
{
"z": 5
}
]
}
]
Are they any plans for supporting objects within arrays without replacing the entire array?
Same for replacing an object:
original
{
"x": "SomeVal",
"y": {
"a": 2,
"b": 3,
"c": 4
}
}
edited
{
"x": "SomeVal",
"y": {}
}
patch
[
{
"op": "remove",
"path": "/y/a"
},
{
"op": "remove",
"path": "/y/b"
},
{
"op": "remove",
"path": "/y/c"
}
]
expected
[
{
"op": "replace",
"path": "/y",
"value": {}
}
]
What would be the expected behavior? Somehow determinate which option would produce the smallest patch?