JsonPatchOperationA single JSON Patch operation.
When to use
Use to manually construct patch operations, accept patch operations from callers, or type-check patch operation structures.
Details
Represents one transformation step in a JSON Patch document. This is a subset
of RFC 6902, restricted to operations that can be applied deterministically
without additional context. All fields are readonly, paths use JSON Pointer
syntax, and the empty string "" refers to the root document. Operations are
discriminated by the op field, and the optional description field can be
used for documentation.
Example (Defining all operation types)
import { JsonPatch } from "effect"
const addOp: JsonPatch.JsonPatchOperation = {
op: "add",
path: "/users/-",
value: { id: 1, name: "Alice" }
}
const removeOp: JsonPatch.JsonPatchOperation = {
op: "remove",
path: "/users/0"
}
const replaceOp: JsonPatch.JsonPatchOperation = {
op: "replace",
path: "/users/0/name",
value: "Bob"
}export type type JsonPatchOperation =
| {
readonly op: "add"
readonly path: string
readonly value: Schema.Json
readonly description?: string
}
| {
readonly op: "remove"
readonly path: string
readonly description?: string
}
| {
readonly op: "replace"
readonly path: string
readonly value: Schema.Json
readonly description?: string
}
A single JSON Patch operation.
When to use
Use to manually construct patch operations, accept patch operations from
callers, or type-check patch operation structures.
Details
Represents one transformation step in a JSON Patch document. This is a subset
of RFC 6902, restricted to operations that can be applied deterministically
without additional context. All fields are readonly, paths use JSON Pointer
syntax, and the empty string "" refers to the root document. Operations are
discriminated by the op field, and the optional description field can be
used for documentation.
Example (Defining all operation types)
import { JsonPatch } from "effect"
const addOp: JsonPatch.JsonPatchOperation = {
op: "add",
path: "/users/-",
value: { id: 1, name: "Alice" }
}
const removeOp: JsonPatch.JsonPatchOperation = {
op: "remove",
path: "/users/0"
}
const replaceOp: JsonPatch.JsonPatchOperation = {
op: "replace",
path: "/users/0/name",
value: "Bob"
}
JsonPatchOperation =
| {
readonly op: "add"op: "add"
/**
* JSON Pointer to the target location. For arrays, the last token may be `-`
* to append.
*
* **When to use**
*
* Use to identify where the `add` operation inserts its value.
*/
readonly path: stringJSON Pointer to the target location. For arrays, the last token may be -
to append.
When to use
Use to identify where the add operation inserts its value.
path: string
readonly value: Schema.Jsonvalue: import SchemaSchema.type Json =
| string
| number
| boolean
| Schema.JsonArray
| Schema.JsonObject
| null
Recursive TypeScript type for any valid immutable JSON value: null,
number, boolean, string, a readonly array of Json values, or a
readonly record of string → Json. For the corresponding schema, see the
Json
const.
Schema that accepts and validates any immutable JSON-compatible value.
Example (Validating a JSON value)
import { Schema } from "effect"
const result = Schema.decodeUnknownOption(Schema.Json)({ key: [1, true, null] })
console.log(result._tag) // "Some"
Json
readonly description?: string | undefineddescription?: string
}
| {
readonly op: "remove"op: "remove"
/**
* JSON Pointer to the target location.
*
* **When to use**
*
* Use to identify which location the `remove` operation deletes.
*/
readonly path: stringJSON Pointer to the target location.
When to use
Use to identify which location the remove operation deletes.
path: string
readonly description?: string | undefineddescription?: string
}
| {
readonly op: "replace"op: "replace"
/**
* JSON Pointer to the target location. Use `""` to replace the root document.
*
* **When to use**
*
* Use to identify which location the `replace` operation overwrites.
*/
readonly path: stringJSON Pointer to the target location. Use "" to replace the root document.
When to use
Use to identify which location the replace operation overwrites.
path: string
readonly value: Schema.Jsonvalue: import SchemaSchema.type Json =
| string
| number
| boolean
| Schema.JsonArray
| Schema.JsonObject
| null
Recursive TypeScript type for any valid immutable JSON value: null,
number, boolean, string, a readonly array of Json values, or a
readonly record of string → Json. For the corresponding schema, see the
Json
const.
Schema that accepts and validates any immutable JSON-compatible value.
Example (Validating a JSON value)
import { Schema } from "effect"
const result = Schema.decodeUnknownOption(Schema.Json)({ key: [1, true, null] })
console.log(result._tag) // "Some"
Json
readonly description?: string | undefineddescription?: string
}