effect-io-ai

Package: effect
Module: JsonPatch

JsonPatch.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

Signature

type JsonPatch = ReadonlyArray<JsonPatchOperation>

Source

Since v4.0.0