Zum Hauptinhalt springen

3. Document Structure (Dokumentstruktur)

3. Document Structure (Dokumentstruktur)

Ein JSON-Patch-Dokument ist ein JSON [RFC4627] Dokument, das ein Array von Objekten darstellt. Jedes Objekt repräsentiert eine einzelne Operation, die auf das Ziel-JSON-Dokument (Target JSON Document) angewendet werden soll.

Das Folgende ist ein Beispiel für ein JSON-Patch-Dokument, das in einer HTTP-PATCH-Anfrage übertragen wird:

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" }
]

Die Auswertung eines JSON-Patch-Dokuments beginnt gegen ein Ziel-JSON-Dokument. Operationen werden sequenziell in der Reihenfolge angewendet, in der sie im Array erscheinen. Jede Operation in der Sequenz wird auf das Zieldokument angewendet; das resultierende Dokument wird zum Ziel der nächsten Operation. Die Auswertung wird fortgesetzt, bis alle Operationen erfolgreich angewendet wurden oder bis eine Fehlerbedingung auftritt.