2

我是 Json 的新手,即 JSON PATCH。我有一个场景,我需要找出同一对象的两个版本的 Json 文件之间,因为我正在使用 json-patch-master。但不幸的是,补丁生成的解释不同,即顺序不同,因此得到意外/无效的结果。谁能帮我在生成 Json Patch 时如何保留订单?

**Here is the actual example.
Original Json file :**

[ {
  "name" : "name1",
  "roolNo" : "1"
}, {
  "name" : "name2",
  "roolNo" : "2"
}, {
  "name" : "name3",
  "roolNo" : "3"
}, {
  "name" : "name4",
  "roolNo" : "4"
} ]


**Modified/New Json file:  i.e. removed 2nd node of original file.**

[ {
  "name" : "name1",
  "roolNo" : "1"
}, {
  "name" : "name3",
  "roolNo" : "3"
}, {
  "name" : "name4",
  "roolNo" : "4"
} ]

**Patch/Diff Generated :**

[ {"op":"remove","path":"/3"},
{"op":"replace","path":"/1/name","value":"name3"},
{"op":"replace","path":"/1/roolNo","value":"3"},
{"op":"replace","path":"/2/name","value":"name4"},
{"op":"replace","path":"/2/roolNo","value":"4"}]

Very time I generate Diff/Patch it is giving different path/diff results.
And moreover the interpretation is different i.e. order is not preserving.

**Is there any way to get expected results i.e. [ {"op":"remove","path":"/1"} ] , in other words generated a patch/diff based some order so will get what is expected. ?
How to handle this kind of scenario ?**

Please help me.

Thank you so much.
~Shyam
4

1 回答 1

0

我们目前正在Starcounter-Jack/JSON-Patch中解决这个问题。

它似乎适用于原生Array.Observe- http://jsfiddle.net/tomalec/p4s7aw96/

尝试Starcounter-Jack/JSON-Patch issues/65_ArrayObserve 分支 ,我们将在检查 shim 和性能后将其作为新版本发布。

随时在JSON-Patch 问题板上添加您的评论

于 2015-04-03T08:56:00.230 回答