JSON Patch...

與上篇一樣,都是在「Please. Don't Patch Like An Idiot.」這篇裡看到的:「JavaScript Object Notation (JSON) Patch」(RFC 6902)。

配合 JSON Pointer (RFC 6901) 的語法,下面的操作很清楚表示了想要做什麼:

[
    { "op": "test", "path": "/a/b/c", "value": "foo" },
    { "op": "remove", "path": "/a/b/c" },
    { "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] },
    { "op": "replace", "path": "/a/b/c", "value": 42 },
    { "op": "move", "from": "/a/b/c", "path": "/a/b/d" },
    { "op": "copy", "from": "/a/b/d", "path": "/a/b/e" }
]

再加上 HTTP header 裡的 If-Match 可以用來處理起始版本,test 也可以阻擋某些異常狀況,基本的都有了?接下來應該找 Canonical JSON 的方案,這樣可以直接拿 hash 的值當版本?

This entry was posted in Computer, Murmuring, Programming and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *