簡體   English   中英

JSON補丁rfc6902:順序操作和索引

[英]JSON patch rfc6902: Sequential operation and index

在JSON補丁中,如何在同一個數組上使用索引進行后續操作。 例如,考慮一下

 var source = { colors: ['Red', 'Green', 'Blue'] };
 var target = { colors: [] }; 

補丁文檔(操作)

[{"op":"remove","path":"/colors/0"},
{"op":"remove","path":"/colors/1"},
{"op":"remove","path":"/colors/2"}]

如果我考慮源的索引,上面的索引是正確的。 當我按順序應用它時,索引不正確。 也就是說,如果我刪除第0個和第1個索引,則索引2處沒有元素。

我可以想到幾種方法來處理這個問題。 對數組進行所有刪除操作的組,然后在刪除期間保留一個臨時結構來保存/操作索引中的更改。 或者,保持索引相對於變異值

[{"op":"remove","path":"/colors/0"},
{"op":"remove","path":"/colors/0"},
{"op":"remove","path":"/colors/0"}]

如果操作被認為是順序資源的變異,那么這是有意義的。

對此有什么標准嗎? 我在規范中看不到任何相關內容。 A.4。 刪除數組元素

對此有什么標准嗎?

關於操作評估部分似乎很清楚:

Evaluation of a JSON Patch document begins against a target JSON
document.  Operations are applied sequentially in the order they
appear in the array.  Each operation in the sequence is applied to
the target document; the resulting document becomes the target of the
next operation.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM