1. 引言 (Introduction)
1. 引言 (Introduction)
本规范定义 JSON merge patch document format, processing rules 以及相关 MIME media type identifier. merge patch format 主要旨在与 HTTP PATCH method [RFC5789] 一起使用, 作为描述对 target resource 内容的一组修改的方式.
JSON merge patch document 使用一种紧密模仿被修改文档的 syntax, 描述要对 target JSON document 进行的更改. merge patch document 的接收方通过比较所提供 patch 的内容与 target document 当前内容, 来确定所请求的确切变更集合. 如果提供的 merge patch 包含 target 中不存在的 members, 则添加这些 members. 如果 target 确实包含该 member, 则替换其值. merge patch 中的 null values 被赋予特殊含义, 表示移除 target 中的现有值.
例如, 给定以下原始 JSON document:
{
"a": "b",
"c": {
"d": "e",
"f": "g"
}
}
可以通过发送以下内容来更改 "a" 的值并移除 "f":
PATCH /target HTTP/1.1
Host: example.org
Content-Type: application/merge-patch+json
{
"a":"z",
"c": {
"f": null
}
}
应用到 target resource 后, "a" member 的值被替换为 "z", "f" 被移除, 其余内容保持不变.
这种设计意味着 merge patch documents 适合描述主要使用 objects 作为结构且不使用显式 null values 的 JSON documents 的修改. merge patch format 并不适用于所有 JSON syntaxes.