JSON8 icon indicating copy to clipboard operation
JSON8 copied to clipboard

Objects with arrays that change create wordy patches

Open bozzaj opened this issue 7 years ago • 2 comments

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?

bozzaj avatar Jul 23 '18 04:07 bozzaj

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": {}
  }
]

smeijer avatar Mar 28 '19 16:03 smeijer

What would be the expected behavior? Somehow determinate which option would produce the smallest patch?

sonnyp avatar Jun 13 '19 11:06 sonnyp