JavaScript Object Notation (JSON) Patch

RFC 6902

この日本語訳は非公式な文書です…
仕様メタデータ

要約

JSON Patch は、 JavaScript Object Notation ( JSON )文書に適用する 一連の演算を表記するための JSON 文書構造を規定する。 これは HTTP PATCH メソッドでの利用に適するものである。 その種のパッチ文書の識別には, "application/json-patch+json" メディア型が利用される。 JSON Patch defines a JSON document structure for expressing a sequence of operations to apply to a JavaScript Object Notation (JSON) document; it is suitable for use with the HTTP PATCH method. The "application/json-patch+json" media type is used to identify such patch documents.

このメモの位置付け

これは、 Internet Standards Track 文書である。 This is an Internet Standards Track document.

この文書は、 IETF よる成果物であり, IETF コミュニティの合意を表現するものである。 それは、公開の評価を受け, IESG から発行が認可されたものである。 Internet 標準についての更なる情報は RFC5741 2 節 に見られる。 This document is a product of the Internet Engineering Task Force (IETF). It represents the consensus of the IETF community. It has received public review and has been approved for publication by the Internet Engineering Steering Group (IESG). Further information on Internet Standards is available in Section 2 of RFC 5741.

この文書の現在の位置付け, 正誤表, フィードバックの仕方についての情報は、 http://www.rfc-editor.org/info/rfc6902 から得られる。 Information about the current status of this document, any errata, and how to provide feedback on it may be obtained at http://www.rfc-editor.org/info/rfc6902.

著作権の告知

Copyright (c) 2013 IETF Trust and the persons identified as the document authors. All rights reserved.

この文書は、その発行の日付から有効な、 BCP 78, および IETF Trust の IETF Documents に対する Legal Provisions Relating の対象になる( http://trustee.ietf.org/license-info )。 これらの文書には,この文書に関するあなたの権利と制約条項が述べらているので、入念に査読されたし。 この文書から取り出された Code Components は、 Trust Legal Provisions の Section 4.e に述べられるように, Simplified BSD License テキストを含んでいなければならず、 Simplified BSD License に記されるように,無保証で提供される。 This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License.

1. 概要

JavaScript Object Notation ( JSON ) [RFC4627] は、構造データの交換と格納のための共通の形式である。 HTTP PATCH [RFC5789] は、 Hypertext Transfer Protocol ( HTTP ) [RFC2616] に,リソースに対する部分的な変更を加えるためのメソッドを追加して それを拡張する。 JavaScript Object Notation (JSON) [RFC4627] is a common format for the exchange and storage of structured data. HTTP PATCH [RFC5789] extends the Hypertext Transfer Protocol (HTTP) [RFC2616] with a method to perform partial modifications to resources.

JSON Patch は、目的の JSON 文書に適用する一連の演算を表記するための(メディア型 "application/json-patch+json" により識別される)文書形式である。 これは HTTP PATCH メソッドでの利用に適するものである。 JSON Patch is a format (identified by the media type "application/json-patch+json") for expressing a sequence of operations to apply to a target JSON document; it is suitable for use with the HTTP PATCH method.

この形式は、 JSON 文書, あるいは同種の拘束を有するデータ構造(すなわち,JSON 文法を利用して,オブジェクトや配列に直列化し得るもの)に対し 部分的な更新が必要とされるような,他の事例にも有用になり得る。 This format is also potentially useful in other cases in which it is necessary to make partial updates to a JSON document or to a data structure that has similar constraints (i.e., they can be serialized as an object or an array using the JSON grammar).

2. 表記規約

この文書におけるキーワード: 「〜しなければ(〜しては)ならない」 = “MUST (NOT)”, 「〜する(〜しない)ものとする」 = “SHALL (NOT)”, 「〜するべきである(でない)」 = “SHOULD (NOT)” は、 RFC2119 [RFC2119] に則って解釈されるものとする。 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 [RFC2119].

3. 文書構造

JSON Patch 文書は、オブジェクトの配列を表現する JSON [RFC4627] 文書である。 各オブジェクトは、目的 JSON 文書に適用される1個の演算を表現する。 A JSON Patch document is a JSON [RFC4627] document that represents an array of objects. Each object represents a single operation to be applied to the target JSON document.

HTTP PATCH リクエストにより転送される JSON Patch 文書の例を示す: The following is an example JSON Patch document, transferred in an HTTP PATCH request:

PATCH /my/data HTTP/1.1
Host: example.org
Content-Length: 326
Content-Type: application/json-patch+json
If-Match: "abc123"
[
  { "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" }
]

JSON Patch 文書の評価は、最初は目的 JSON 文書に対するものとして開始される。 各演算は、配列内に現れる順に,逐次的に適用され、適用される度に,その結果の文書が次の演算の目的文書になる。 評価は、すべての演算が成功裡に適用されるか, またはエラー状態に遭遇するまで継続される。 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. Evaluation continues until all operations are successfully applied or until an error condition is encountered.

4. 演算

演算オブジェクトは、きっかり1個の "op" メンバを持たなければならない。 このメンバは,目的文書にて遂行される演算の種類を指示するものであり、その値は "add", "remove", "replace", "move", "copy", "test" のいずれかでなければならず,他の値はエラーである。 各種オブジェクトの意味論は後続の節にて規定される。 Operation objects MUST have exactly one "op" member, whose value indicates the operation to perform. Its value MUST be one of "add", "remove", "replace", "move", "copy", or "test"; other values are errors. The semantics of each object is defined below.

加えて、演算オブジェクトは,きっかり1個の "path" メンバを持たなければならない。 そのメンバの値は、目的文書の中で演算が遂行される地点( “目的地点” )を指す, JSON-Pointer 値 [RFC6901] を与える文字列である。 Additionally, operation objects MUST have exactly one "path" member. That member's value is a string containing a JSON-Pointer value [RFC6901] that references a location within the target document (the "target location") where the operation is performed.

演算オブジェクトの他のメンバの意味は,演算の種別ごとに規定される(後続の下位節にて述べる)。 明示的に 当該の演算に関わるものと規定されていないメンバは、無視されなければならない(すなわち,演算は、その演算に無関係なメンバについては オブジェクトに元々無かったかのように,遂行されることになる)。 The meanings of other operation object members are defined by operation (see the subsections below). Members that are not explicitly defined for the operation in question MUST be ignored (i.e., the operation will complete as if the undefined member did not appear in the object).

JSON オブジェクトの中でのメンバの順序付けは、有意でないことに注意。 したがって、次の演算オブジェクトは,いずれも等価である: Note that the ordering of members in JSON objects is not significant; therefore, the following operation objects are equivalent:

{ "op": "add", "path": "/a/b/c", "value": "foo" }
{ "path": "/a/b/c", "op": "add", "value": "foo" }
{ "value": "foo", "path": "/a/b/c", "op": "add" }

演算は、 JSON 文書が表現するデータ構造に(すなわち エスケープ( [RFC4627], 2.5 節 )が展開された後に),適用される。 Operations are applied to the data structures represented by a JSON document, i.e., after any unescaping (see [RFC4627], Section 2.5) takes place.

4.1. add

"add" 演算は、目的地点が指しているものに応じて,次のいずれかを遂行する: The "add" operation performs one of the following functions, depending upon what the target location references:

  • 目的地点が 配列 index を指定している場合、その配列の中の 指定された index の位置に,新たな値が挿入される。 【 index 0 が先頭を指す: [RFC6901] の 4 節 Evaluation和訳) 】 If the target location specifies an array index, a new value is inserted into the array at the specified index.
  • 目的地点が 存在しないオブジェクトメンバを指定している場合、そのオブジェクトに新たなメンバが追加される。 If the target location specifies an object member that does not already exist, a new member is added to the object.
  • 目的地点が 既存のオブジェクトメンバを指定している場合、そのメンバの値が置換される。 If the target location specifies an object member that does exist, that member's value is replaced.

演算オブジェクトは、追加のための値をとる, "value" メンバを持っていなければならない The operation object MUST contain a "value" member whose content specifies the value to be added.

例: For example:

{ "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] }

目的地点は、演算が適用される時点で,次のいずれかを参照していなければならない When the operation is applied, the target location MUST reference one of:

  • 目的文書のルート — その結果,目的文書の内容全体が,指定された値に置き換わる†。 The root of the target document - whereupon the specified value becomes the entire content of the target document.

    【† 指定された値がオブジェクトでも配列でもない場合の結果は、 RFC 4627 では,合法でない JSON 文書にされていたが、 RFC 4627 を置き換える RFC 7159 により, 合法にされた

  • 既存のオブジェクトに追加するメンバ — その結果、そのオブジェクトの中の指示された地点に,指定された値が追加される。 そのメンバが既存のものであった場合、それは指定された値に置換される。 A member to add to an existing object - whereupon the supplied value is added to that object at the indicated location. If the member already exists, it is replaced by the specified value.
  • 既存の配列に追加する要素 — その結果、その配列の中の指示された地点に,指定された値が追加される。 指定された index 以上に位置する要素は,1つずつ後ろへずらされる。 指定された index が配列の要素数を超えてはならない 【 index が要素数に等しければ,末尾に付加 】 。 配列の末尾 index を表す文字 "-" が利用された場合( [RFC6901] を参照)、値は配列の末尾に付加されることになる。 An element to add to an existing array - whereupon the supplied value is added to the array at the indicated location. Any elements at or above the specified index are shifted one position to the right. The specified index MUST NOT be greater than the number of elements in the array. If the "-" character is used to index the end of the array (see [RFC6901]), this has the effect of appending the value to the array.

この演算は,既存のオブジェクトや配列に値を追加するためにあるので、目的地点に値が存在しないことも度々あり得る。 したがって, 【 RFC6901 の規定により】 ポインタのエラーを取り扱うアルゴリズムが呼び出されることになるが、この仕様は、 "add" の下での,ポインタのエラーの際のふるまいを、そのエラーを無視し, 指定された値を追加するものと定める。 Because this operation is designed to add to existing objects and arrays, its target location will often not exist. Although the pointer's error handling algorithm will thus be invoked, this specification defines the error handling behavior for "add" pointers to ignore that error and add the value as specified.

しかしながら、それを含むオブジェクト自身または配列は,存在する必要があり、不在の場合はエラーになる。 例えば、次の文書から演算が開始されるときの,目的地点 "/a/b" による "add" は: However, the object itself or an array containing it does need to exist, and it remains an error for that not to be the case. For example, an "add" with a target location of "/a/b" starting with this document:

{ "a": { "foo": 1 } }

"a" が存在するのでエラーではなく,その値に "b" に追加されることになる一方、次の文書の場合は: is not an error, because "a" exists, and "b" will be added to its value. It is an error in this document:

{ "q": { "bar": 2 } }

"a" が存在しないのでエラーになる。 because "a" does not exist.

4.2. remove

"remove" 演算は、目的地点から値を除去する。 The "remove" operation removes the value at the target location.

演算が成功とされるためには、目的地点が存在しなければならない The target location MUST exist for the operation to be successful.

例: For example:

{ "op": "remove", "path": "/a/b/c" }

配列から要素が除去される際には、指定された index より先の要素は1つずつ先頭へずらされる。 If removing an element from an array, any elements above the specified index are shifted one position to the left.

4.3. replace

"replace" 演算は、目的地点の値を新たな値で置換する。 演算オブジェクトは、置換のための値をとる "value" メンバを持っていなければならない The "replace" operation replaces the value at the target location with a new value. The operation object MUST contain a "value" member whose content specifies the replacement value.

演算が成功とされるためには、目的地点が存在しなければならない The target location MUST exist for the operation to be successful.

例: For example:

{ "op": "replace", "path": "/a/b/c", "value": 42 }

この演算は、 "remove" 演算の直後に,同じ地点に,置換のための値を "add" 演算により追加するのと、機能的に同じになる。 This operation is functionally identical to a "remove" operation for a value, followed immediately by an "add" operation at the same location with the replacement value.

4.4. move

"move" 演算は、指定された地点から値を除去して,目的地点にその値を追加する。 The "move" operation removes the value at a specified location and adds it to the target location.

演算オブジェクトは、目的文書内の,値の移動元の地点を指す JSON Pointer 文字列値をとる, "from" メンバを含んでいなければならない The operation object MUST contain a "from" member, which is a string containing a JSON Pointer value that references the location in the target document to move the value from.

演算が成功とされるためには、 "from" 地点が存在しなければならない The "from" location MUST exist for the operation to be successful.

例: For example:

{ "op": "move", "from": "/a/b/c", "path": "/a/b/d" }

この演算は、 "from" 地点に対する "remove" 演算の直後に,その除去された値を, "add" 演算により目的地点に追加するのと、機能的に同じになる。 This operation is functionally identical to a "remove" operation on the "from" location, followed immediately by an "add" operation at the target location with the value that was just removed.

【 従って、移動先の目的地点は,除去された後の状態を基に適用されることになる(特に配列要素を移動させる場合に注意:用例 A.7 を参照)。 】

値をその子孫へ移動させることはできない。 すなわち, "from" が指す地点が "path" が指す地点の適正な真の接頭辞になってはならない The "from" location MUST NOT be a proper prefix of the "path" location; i.e., a location cannot be moved into one of its children.

【 “真の接頭辞” ( proper prefix ) — 上の例で述べるなら, "from" が "path" の先頭部分 "/a/b" や "/a" になってはならないが, "path" と同じ "/a/b/d" は許容される。 (文字列として先頭一致する場合でも,例えば "from" が "/a" で "path" が "/ab/c" のような場合は、子孫ではないので “真の接頭辞” とはみなされない。) 】

4.5. copy

"copy" 演算は、指定された地点から目的地点へ値を複製する。 The "copy" operation copies the value at a specified location to the target location.

演算オブジェクトには、目的文書の中の複製元の値の地点を指す JSON Pointer 文字列値をとる, "from" メンバが含まれていなければならない The operation object MUST contain a "from" member, which is a string containing a JSON Pointer value that references the location in the target document to copy the value from.

演算が成功とされるためには、 "from" 地点が存在しなければならない The "from" location MUST exist for the operation to be successful.

例: For example:

{ "op": "copy", "from": "/a/b/c", "path": "/a/b/e" }

この演算は、 "from" メンバにより指定される値を, "add" 演算により目的地点に追加するのと、機能的に同じになる。 This operation is functionally identical to an "add" operation at the target location using the value specified in the "from" member.

4.6. test

"test" 演算は、目的地点の値が指定された値に等しいかどうかテストする。 The "test" operation tests that a value at the target location is equal to a specified value.

演算オブジェクトには、目的地点の値と比較するための値をとる, "value" メンバが含まれていなければならない The operation object MUST contain a "value" member that conveys the value to be compared to the target location's value.

演算が成功と見なされるためには、目的地点の値が "value" の値と等しくなければならない The target location MUST be equal to the "value" value for the operation to be considered successful.

ここで “等しい” とは、目的地点の値と "value" の値が同じ JSON 型であって, かつ その型に応じて、次の規則に則って等しいとされることを意味する: Here, "equal" means that the value at the target location and the value conveyed by "value" are of the same JSON type, and that they are considered equal by the following rules for that type:

文字列の場合

互いに同じ個数の Unicode 文字からなり,それぞれの符号位置がバイトごとに等しいとき、等しいとされる。 strings: are considered equal if they contain the same number of Unicode characters and their code points are byte-by-byte equal.

【 バイトごとに( byte-by-byte ) — Unicode の正準等価などの文字の等価性についての種々の概念は適用せずに,単に符号単位に基づく比較を行うことを指しているものと見られる。 】

数値の場合

互いの値が数値的に等しいとき、等しいとされる。 numbers: are considered equal if their values are numerically equal.

配列の場合

互いの要素数が同じであり、かつ 互いの配列の中の同じ位置の値それぞれが,この型別の比較規則リストの下に 等しいとされるとき、等しいとされる。 arrays: are considered equal if they contain the same number of values, and if each value can be considered equal to the value at the corresponding position in the other array, using this list of type-specific rules.

オブジェクトの場合

(1) 同じ個数のメンバからなり, かつ (2) それらのメンバの(文字列としての)キー名の集合が同じであり, かつ (3) それらのメンバの同じ名前のキーに対応する値が,この型別の比較規則リストの下に 等しいとされるとき、等しいとされる。 objects: are considered equal if they contain the same number of members, and if each member can be considered equal to a member in the other object, by comparing their keys (as strings) and their values (using this list of type-specific rules).

リテラル( false, true, null )の場合

2つの値が同じとき,等しいとされる。 literals (false, true, and null): are considered equal if they are the same.

比較は論理的に 【 すなわち, JSON オブジェクトとして解釈された後に 】 行われることに注意。 例えば、配列のメンバ値の合間の空白類は,比較においては有意でない。 Note that the comparison that is done is a logical comparison; e.g., whitespace between the member values of an array is not significant.

オブジェクトメンバの直列化における順序付けも有意でないことに注意。 Also, note that ordering of the serialization of object members is not significant.

例: For example:

{ "op": "test", "path": "/a/b/c", "value": "foo" }

5. エラーの取り扱い

JSON Patch 文書の規範的な要件に違反している場合, あるいは 演算が成功裡に終わらなかった場合、 JSON Patch 文書の評価は終了されるべきであり,パッチ文書全体の適用は成功とは見なされないものとする If a normative requirement is violated by a JSON Patch document, or if an operation is not successful, evaluation of the JSON Patch document SHOULD terminate and application of the entire patch document SHALL NOT be deemed successful.

【 “べき” — HTTP PATCH メソッドの下での利用では,下記により “中途半端な成功” は明確に排除されているが、他の状況下では,選択の余地が残された記述になっている。 】

[RFC5789], 2.2 節 にて、 JSON Patch が HTTP PATCH メソッドに利用されたときに,エラー状態に遭遇した際の取り扱いが(種々のエラー状態を指示するための,示唆される応答コードなども含め)挙げられている。 See [RFC5789], Section 2.2 for considerations regarding handling errors when JSON Patch is used with the HTTP PATCH method, including suggested status codes to use to indicate various conditions.

[RFC5789] に則り, HTTP PATCH メソッドは不可分的( atomic )になることに注意。 したがって,次のようなパッチでは、いかなる変更も文書に加えられないことになる( "test" 演算の結果がエラーになるので): Note that the HTTP PATCH method is atomic, as per [RFC5789]. Therefore, the following patch would result in no changes being made to the document at all (because the "test" operation results in an error):

[
  { "op": "replace", "path": "/a/b/c", "value": 42 },
  { "op": "test", "path": "/a/b/c", "value": "C" }
]

6. IANA 考慮点

JSON Patch 文書の Internet メディア型は application/json-patch+json である。 The Internet media type for a JSON Patch document is application/ json-patch+json.

型名Type name
applicationapplication
下位型名Subtype name
json-patch+jsonjson-patch+json
必須パラメタRequired parameters
なしnone
オプションのパラメタOptional parameters
なしnone
符号化法についての考慮点Encoding considerations
バイナリbinary
保安上の考慮点Security considerations
7 節,保安上の考慮点を見よ。See Security Considerations in Section 7.
相互運用性についての考慮点Interoperability considerations
N/A
発行仕様Published specification
RFC 6902
このメディア型のアプリケーションApplications that use this media type
JSON 文書を操作するアプリケーション。Applications that manipulate JSON documents.
追記情報Additional information
  • マジックナンバー:N/AMagic number(s): N/A
  • ファイル名拡張子: .json-patchFile extension(s): .json-patch
  • Macintosh ファイルタイプコード: TEXTMacintosh file type code(s): TEXT
更なる情報についての連絡先Person & email address to contact for further information
Paul C. Bryan <pbryan@anode.ca>Paul C. Bryan <pbryan@anode.ca>
意図されている用途Intended usage
COMMONCOMMON
利用における制約Restrictions on usage
なしnone
著作者Author
Paul C. Bryan <pbryan@anode.ca>Paul C. Bryan <pbryan@anode.ca>
変更管理Change controller
IETF

7. 保安上の考慮点

この仕様の保安上の考慮点は、 JSON [RFC4627] と JSON Pointer [RFC6901] と同じである。 This specification has the same security considerations as JSON [RFC4627] and JSON-Pointer [RFC6901].

少数の旧式ウェブブラウザにおいては、認証アクセスの下でも,ルートが配列であるような任意の JSON 文書の読み込みにおいて, 機密を要する情報が含まれている JSON Patch 文書が攻撃者に公開され得る。 これは Cross-Site Request Forgery ( CSRF ) CSRF] として知られている。 A few older Web browsers can be coerced into loading an arbitrary JSON document whose root is an array, leading to a situation in which a JSON Patch document containing sensitive information could be exposed to attackers, even if access is authenticated. This is known as a Cross-Site Request Forgery (CSRF) attack [CSRF].

しかしながら、その種のブラウザは限られた範囲でしか利用されていない(この仕様が書かれた時点での利用率は,概算で市場の 1% に満たないものと推定されている)。 にも拘らず,この攻撃について懸念があるならば、その種の文書が HTTP GET から利用されるのを避けるよう忠告する。 However, such browsers are not widely used (at the time of writing, it is estimated that they are used in less than 1% of the market). Publishers who are nevertheless concerned about this attack are advised to avoid making such documents available with HTTP GET.

8. 謝辞

提案, フィードバック, 言い回しなど,この仕様に寄与された次の方々に感謝する: The following individuals contributed ideas, feedback and wording to this specification:

Mike Acar, Mike Amundsen, Cyrus Daboo, Paul Davis, Stefan Koegl, Murray S. Kucherawy, Dean Landolt, Randall Leeds, James Manger, Julian Reschke, James Snell, Eli Stevens, and Henry S. Thompson.

JSON Patch 文書の構造は、 XMLPatch 文書仕様 [RFC5261] から影響を受けている。 The structure of a JSON Patch document was influenced by the XML Patch document specification [RFC5261].

付録 A. 用例集

A.1. オブジェクトメンバの追加

目的 JSON 文書の例: An example target JSON document:

{ "foo": "bar"}

JSON Patch 文書: A JSON Patch document:

[
  { "op": "add", "path": "/baz", "value": "qux" }
]

結果の JSON 文書: The resulting JSON document:

{
  "baz": "qux",
  "foo": "bar"
}

A.2. 配列要素の追加

目的 JSON 文書の例: An example target JSON document:

{ "foo": [ "bar", "baz" ] }

JSON Patch 文書: A JSON Patch document:

[
  { "op": "add", "path": "/foo/1", "value": "qux" }
]

結果の JSON 文書: The resulting JSON document:

{ "foo": [ "bar", "qux", "baz" ] }

A.3. オブジェクトメンバの除去

目的 JSON 文書の例: An example target JSON document:

{
  "baz": "qux",
  "foo": "bar"
}

JSON Patch 文書: A JSON Patch document:

[
  { "op": "remove", "path": "/baz" }
]

結果の JSON 文書: The resulting JSON document:

{ "foo": "bar" }

A.4. 配列要素の除去

目的 JSON 文書の例: An example target JSON document:

{ "foo": [ "bar", "qux", "baz" ] }

JSON Patch 文書: A JSON Patch document:

[
  { "op": "remove", "path": "/foo/1" }
]

結果の JSON 文書: The resulting JSON document:

{ "foo": [ "bar", "baz" ] }

A.5. 値の置換

目的 JSON 文書の例: An example target JSON document:

{
  "baz": "qux",
  "foo": "bar"
}

JSON Patch 文書: A JSON Patch document:

[
  { "op": "replace", "path": "/baz", "value": "boo" }
]

結果の JSON 文書: The resulting JSON document:

{
  "baz": "boo",
  "foo": "bar"
}

A.6. 値の移動

目的 JSON 文書の例: An example target JSON document:

{
  "foo": {
    "bar": "baz",
    "waldo": "fred"
  },
  "qux": {
    "corge": "grault"
  }
}

JSON Patch 文書: A JSON Patch document:

[
  { "op": "move", "from": "/foo/waldo", "path": "/qux/thud" }
]

結果の JSON 文書: The resulting JSON document:

{
  "foo": {
    "bar": "baz"
  },
  "qux": {
    "corge": "grault",
    "thud": "fred"
  }
}

A.7. 配列要素の移動

目的 JSON 文書の例: An example target JSON document:

{ "foo": [ "all", "grass", "cows", "eat" ] }

JSON Patch 文書: A JSON Patch document:

[
  { "op": "move", "from": "/foo/1", "path": "/foo/3" }
]

結果の JSON 文書: The resulting JSON document:

{ "foo": [ "all", "cows", "eat", "grass" ] }

A.8. 値のテスト(成功)

目的 JSON 文書の例: An example target JSON document:

{
  "baz": "qux",
  "foo": [ "a", 2, "c" ]
}

次の JSON Patch 文書は成功裡に評価される: A JSON Patch document that will result in successful evaluation:

[
  { "op": "test", "path": "/baz", "value": "qux" },
  { "op": "test", "path": "/foo/1", "value": 2 }
]

A.9. 値のテスト(エラー)

目的 JSON 文書の例: An example target JSON document:

{ "baz": "qux" }

次の JSON Patch 文書はエラー状態になる: A JSON Patch document that will result in an error condition:

[
  { "op": "test", "path": "/baz", "value": "bar" }
]

A.10. 入れ子のメンバオブジェクトの追加

目的 JSON 文書の例: An example target JSON document:

{ "foo": "bar" }

JSON Patch 文書: A JSON Patch document:

[
  { "op": "add", "path": "/child", "value": { "grandchild": { } } }
]

結果の JSON 文書: The resulting JSON document:

{
  "foo": "bar",
  "child": {
    "grandchild": {
    }
  }
}

A.11. 認識されない要素の無視

目的 JSON 文書の例: An example target JSON document:

{ "foo": "bar" }

JSON Patch 文書: A JSON Patch document:

[
  { "op": "add", "path": "/baz", "value": "qux", "xyz": 123 }
]

結果の JSON 文書: The resulting JSON document:

{
  "foo": "bar",
  "baz": "qux"
}

A.12. 存在しない目的地点を伴う追加

目的 JSON 文書の例: An example target JSON document:

{ "foo": "bar" }

JSON Patch 文書: A JSON Patch document:

[
  { "op": "add", "path": "/baz/bat", "value": "qux" }
]

この JSON Patch 文書が上の目的 JSON 文書に適用されたときの結果は,エラーになる(したがって,適用されない)。 "add" 演算の目的地点は[ 文書のルート, 既存のオブジェクトのメンバ, 既存の配列のメンバ ]のいずれも指していないので。 This JSON Patch document, applied to the target JSON document above, would result in an error (therefore, it would not be applied), because the "add" operation's target location that references neither the root of the document, nor a member of an existing object, nor a member of an existing array.

A.13. 無効な JSON Patch 文書

JSON Patch 文書: A JSON Patch document:

[
  { "op": "add", "path": "/baz", "value": "qux", "op": "remove" }
]

この JSON Patch 文書は、 "add" 演算を持つものとは見なされない。 後続に "op":"remove" があるので。 JSON のオブジェクトメンバ名は一意的である “べき” とされているので、メンバ名の重複の際の取り扱いは標準的な意味ではエラーにはされないが。 This JSON Patch document cannot be treated as an "add" operation, because it contains a later "op":"remove" element. JSON requires that object member names be unique with a "SHOULD" requirement, and there is no standard error handling for duplicates.

A.14. “~” エスケープの取り扱い

目的 JSON 文書の例: An example target JSON document:

{
  "/": 9,
  "~1": 10
}

JSON Patch 文書: A JSON Patch document:

[
  {"op": "test", "path": "/~01", "value": 10}
]

結果の JSON 文書: The resulting JSON document:

{
  "/": 9,
  "~1": 10
}

【 JSON Pointer "/~01" の “~” エスケープは "~0" のみ展開され,それ以上は展開されない( "~0" の展開は "~1" の後なので — [RFC6901] の 4 節 Evaluation和訳)。 】

A.15. 文字列と数値の比較

目的 JSON 文書の例: An example target JSON document:

{
  "/": 9,
  "~1": 10
}

JSON Patch 文書: A JSON Patch document:

[
  {"op": "test", "path": "/~01", "value": "10"}
]

この結果はテストが失敗するのでエラーになる。 文書の方の値は数値である一方,テストされる値は文字列なので。 This results in an error, because the test fails. The document value is numeric, whereas the value being tested for is a string.

A.16. 配列値の追加

目的 JSON 文書の例: An example target JSON document:

{ "foo": ["bar"] }

JSON Patch 文書: A JSON Patch document:

[
  { "op": "add", "path": "/foo/-", "value": ["abc", "def"] }
]

結果の JSON 文書: The resulting JSON document:

{ "foo": ["bar", ["abc", "def"]] }