Package: effect
Module: JsonPatch
A JSON Patch document (an ordered list of operations).
When to use
Use to store, serialize, pass, or validate complete patch documents.
Details
Represents a complete transformation as a readonly sequence of immutable operations. Operations are applied sequentially from first to last, and later operations observe the document state produced by earlier operations. An empty array represents a no-op patch and returns the original document.
Example (Defining a multi-operation patch)
import { JsonPatch } from "effect"
const patch: JsonPatch.JsonPatch = [
{ op: "add", path: "/items/-", value: "apple" },
{ op: "replace", path: "/count", value: 5 },
{ op: "remove", path: "/oldField" }
]
const result = JsonPatch.apply(patch, { count: 3, oldField: "value" })
// { count: 5, items: ["apple"] }
See
JsonPatchOperation for individual operation typesget to generate patches from value differencesapply to execute patches to transform documentsSignature
type JsonPatch = ReadonlyArray<JsonPatchOperation>
Since v4.0.0