<T>(schema: ConstraintCodec<T, unknown>): Differ<T, JsonPatch.JsonPatch>Derives a JSON Patch differ from a codec. Serializes values to JSON (via toCodecJson), computes RFC 6902 JSON Patch operations between old and new values, and can apply patches back to the typed value.
export function function toDifferJsonPatch<T>(
schema: ConstraintCodec<T, unknown>
): Differ<T, JsonPatch.JsonPatch>
Derives a JSON Patch differ from a codec. Serializes values to JSON (via
toCodecJson
), computes RFC 6902 JSON Patch operations between old
and new values, and can apply patches back to the typed value.
toDifferJsonPatch<function (type parameter) T in toDifferJsonPatch<T>(schema: ConstraintCodec<T, unknown>): Differ<T, JsonPatch.JsonPatch>T>(schema: ConstraintCodec<T, unknown>(parameter) schema: {
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
ast: SchemaAST.AST;
Iso: unknown;
}
schema: interface ConstraintCodec<out T, out E = T, out RD = never, out RE = never>Lightweight structural constraint for APIs that need codec type views but do
not need the full schema protocol.
When to use
Use when you need to preserve decoded type, encoded type, and service
requirements for a schema value, but the API does not call schema methods
such as annotate, check, rebuild, make, or makeEffect.
ConstraintCodec<function (type parameter) T in toDifferJsonPatch<T>(schema: ConstraintCodec<T, unknown>): Differ<T, JsonPatch.JsonPatch>T, unknown>): interface Differ<in out T, in out Patch>Describes how to compute, combine, and apply patches for values of type T.
When to use
Use to model patch-based updates for a value type when callers need to
compute a patch from two values, combine patches, and apply a patch later.
Details
A Differ provides an empty patch, computes the patch between two values,
combines patches, and applies a patch to an old value to produce an updated
value.
Differ<function (type parameter) T in toDifferJsonPatch<T>(schema: ConstraintCodec<T, unknown>): Differ<T, JsonPatch.JsonPatch>T, import JsonPatchJsonPatch.type JsonPatch =
readonly JsonPatch.JsonPatchOperation[]
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"] }
JsonPatch> {
const const serializer: toCodecJson<
ConstraintCodec<T, unknown, never, never>
>
const serializer: {
Type: S["Type"];
Encoded: Json;
DecodingServices: S["DecodingServices"];
EncodingServices: S["EncodingServices"];
Iso: S["Iso"];
schema: S;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Annotations.Bottom<T, any>) => toCodecJson<ConstraintCodec<T, unknown, never, never>>;
annotateKey: (annotations: Annotations.Key<T>) => toCodecJson<ConstraintCodec<T, unknown, never, never>>;
check: (checks_0: SchemaAST.Check<T>, ...checks: Array<SchemaAST.Check<T>>) => toCodecJson<ConstraintCodec<T, unknown, never, never>>;
rebuild: (ast: SchemaAST.AST) => toCodecJson<ConstraintCodec<T, unknown, never, never>>;
make: (input: unknown, options?: MakeOptions) => T;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<T>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<T, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
serializer = function toCodecJson<
S extends Constraint
>(schema: S): toCodecJson<S>
Derives a canonical JSON codec from a schema. The encoded form is Json, and
decoding produces the schema's Type.
toCodecJson(schema: ConstraintCodec<T, unknown>(parameter) schema: {
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
ast: SchemaAST.AST;
Iso: unknown;
}
schema)
const const get: (
input: T,
options?: SchemaAST.ParseOptions
) => Json
get = import SchemaParserSchemaParser.const encodeSync: <
S extends Schema.ConstraintEncoder<unknown>
>(
schema: S,
options?: SchemaAST.ParseOptions
) => (
input: S["Type"],
options?: SchemaAST.ParseOptions
) => S["Encoded"]
Creates a synchronous encoder for input already typed as the schema's decoded
Type.
When to use
Use to encode already typed schema values synchronously when encoding failure
should throw an Error whose cause is SchemaIssue.Issue.
Details
The returned function returns the schema's Encoded value on success and throws
an Error with the SchemaIssue.Issue in its cause on encoding failure.
Gotchas
Causes that contain defects, interruptions, or asynchronous work at this
synchronous boundary throw an Error whose cause is the underlying Cause,
instead of being converted to a schema validation error.
encodeSync(const serializer: toCodecJson<
ConstraintCodec<T, unknown, never, never>
>
const serializer: {
Type: S["Type"];
Encoded: Json;
DecodingServices: S["DecodingServices"];
EncodingServices: S["EncodingServices"];
Iso: S["Iso"];
schema: S;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Annotations.Bottom<T, any>) => toCodecJson<ConstraintCodec<T, unknown, never, never>>;
annotateKey: (annotations: Annotations.Key<T>) => toCodecJson<ConstraintCodec<T, unknown, never, never>>;
check: (checks_0: SchemaAST.Check<T>, ...checks: Array<SchemaAST.Check<T>>) => toCodecJson<ConstraintCodec<T, unknown, never, never>>;
rebuild: (ast: SchemaAST.AST) => toCodecJson<ConstraintCodec<T, unknown, never, never>>;
make: (input: unknown, options?: MakeOptions) => T;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<T>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<T, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
serializer)
const const set: (
input: Json,
options?: SchemaAST.ParseOptions
) => T
set = import SchemaParserSchemaParser.const decodeSync: <
S extends Schema.ConstraintDecoder<unknown>
>(
schema: S,
options?: SchemaAST.ParseOptions
) => (
input: S["Encoded"],
options?: SchemaAST.ParseOptions
) => S["Type"]
Creates a synchronous decoder for input already typed as the schema's Encoded
type.
When to use
Use to decode values already typed as the schema's Encoded input when
decoding failure should throw an Error whose cause is SchemaIssue.Issue.
Details
The returned function returns the decoded Type on success and throws an
Error with the SchemaIssue.Issue in its cause on decoding failure.
Gotchas
Causes that contain defects, interruptions, or asynchronous work at this
synchronous boundary throw an Error whose cause is the underlying Cause,
instead of being converted to a schema validation error.
decodeSync(const serializer: toCodecJson<
ConstraintCodec<T, unknown, never, never>
>
const serializer: {
Type: S["Type"];
Encoded: Json;
DecodingServices: S["DecodingServices"];
EncodingServices: S["EncodingServices"];
Iso: S["Iso"];
schema: S;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Annotations.Bottom<T, any>) => toCodecJson<ConstraintCodec<T, unknown, never, never>>;
annotateKey: (annotations: Annotations.Key<T>) => toCodecJson<ConstraintCodec<T, unknown, never, never>>;
check: (checks_0: SchemaAST.Check<T>, ...checks: Array<SchemaAST.Check<T>>) => toCodecJson<ConstraintCodec<T, unknown, never, never>>;
rebuild: (ast: SchemaAST.AST) => toCodecJson<ConstraintCodec<T, unknown, never, never>>;
make: (input: unknown, options?: MakeOptions) => T;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<T>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<T, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
serializer)
return {
Differ<T, JsonPatch>.empty: JsonPatch.JsonPatchempty: [],
Differ<T, JsonPatch>.diff(oldValue: T, newValue: T): JsonPatch.JsonPatchdiff: (oldValue: ToldValue, newValue: TnewValue) => import JsonPatchJsonPatch.function get(
oldValue: Schema.Json,
newValue: Schema.Json
): JsonPatch
Computes a structural patch that transforms oldValue into newValue.
When to use
Use to compute a JSON Patch from before and after JSON documents, detect
structural changes, or create deterministic update operations.
Details
Generates a structural diff between two JSON values, producing a patch that
yields newValue when applied to oldValue. It returns an empty array when
values are identical, recursively diffs nested structures, emits root
replace operations for primitive changes, and processes object keys in
sorted order for stable output.
Gotchas
Arrays are compared by index position, with no move or copy detection. Array
removals are emitted from highest to lowest index to prevent index shifting.
The output is deterministic but not guaranteed to be minimal.
Example (Computing object diff)
import { JsonPatch } from "effect"
const oldValue = { users: [{ id: 1, name: "Alice" }], count: 1 }
const newValue = { users: [{ id: 1, name: "Bob" }, { id: 2, name: "Charlie" }], count: 2 }
const patch = JsonPatch.get(oldValue, newValue)
// [
// { op: "replace", path: "/users/0/name", value: "Bob" },
// { op: "add", path: "/users/1", value: { id: 2, name: "Charlie" } },
// { op: "replace", path: "/count", value: 2 }
// ]
get(const get: (
input: T,
options?: SchemaAST.ParseOptions
) => Json
get(oldValue: ToldValue), const get: (
input: T,
options?: SchemaAST.ParseOptions
) => Json
get(newValue: TnewValue)),
Differ<T, JsonPatch>.combine(first: JsonPatch.JsonPatch, second: JsonPatch.JsonPatch): JsonPatch.JsonPatchcombine: (first: JsonPatch.JsonPatch(parameter) first: {
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<JsonPatch.JsonPatchOperation>>): Array<JsonPatch.JsonPatchOperation>; (...items: Array<JsonPatch.JsonPatchOperation | ConcatArray<JsonPatch.JsonPatchOperation>>): Array<JsonPatch.JsonPatchOperation> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<JsonPatch.JsonPatchOperation>;
indexOf: (searchElement: JsonPatch.JsonPatchOperation, fromIndex?: number) => number;
lastIndexOf: (searchElement: JsonPatch.JsonPatchOperation, fromIndex?: number) => number;
every: { (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: JsonPatch.JsonPatchOperation, index: number, ar…;
some: (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => void, thisArg?: any) => void;
map: (callbackfn: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => value is S, thisArg?: any): Array<S>; (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: Readonl…;
reduce: { (callbackfn: (previousValue: JsonPatch.JsonPatchOperation, currentValue: JsonPatch.JsonPatchOperation, currentIndex: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => JsonPatch.JsonPatchOperation): JsonPatch.JsonPatchOperati…;
reduceRight: { (callbackfn: (previousValue: JsonPatch.JsonPatchOperation, currentValue: JsonPatch.JsonPatchOperation, currentIndex: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => JsonPatch.JsonPatchOperation): JsonPatch.JsonPatchOperati…;
find: { (predicate: (value: JsonPatch.JsonPatchOperation, index: number, obj: ReadonlyArray<JsonPatch.JsonPatchOperation>) => value is S, thisArg?: any): S | undefined; (predicate: (value: JsonPatch.JsonPatchOperation, index: number, obj: Readon…;
findIndex: (predicate: (value: JsonPatch.JsonPatchOperation, index: number, obj: ReadonlyArray<JsonPatch.JsonPatchOperation>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, JsonPatch.JsonPatchOperation]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<JsonPatch.JsonPatchOperation>;
includes: (searchElement: JsonPatch.JsonPatchOperation, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: JsonPatch.JsonPatchOperation, index: number, array: Array<JsonPatch.JsonPatchOperation>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => JsonPatch.JsonPatchOperation | undefined;
findLast: { (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => value is S, thisArg?: any): S | undefined; (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: Re…;
findLastIndex: (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => unknown, thisArg?: any) => number;
toReversed: () => Array<JsonPatch.JsonPatchOperation>;
toSorted: (compareFn?: ((a: JsonPatch.JsonPatchOperation, b: JsonPatch.JsonPatchOperation) => number) | undefined) => Array<JsonPatch.JsonPatchOperation>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<JsonPatch.JsonPatchOperation>): Array<JsonPatch.JsonPatchOperation>; (start: number, deleteCount?: number): Array<JsonPatch.JsonPatchOperation> };
with: (index: number, value: JsonPatch.JsonPatchOperation) => Array<JsonPatch.JsonPatchOperation>;
}
first, second: JsonPatch.JsonPatch(parameter) second: {
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<JsonPatch.JsonPatchOperation>>): Array<JsonPatch.JsonPatchOperation>; (...items: Array<JsonPatch.JsonPatchOperation | ConcatArray<JsonPatch.JsonPatchOperation>>): Array<JsonPatch.JsonPatchOperation> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<JsonPatch.JsonPatchOperation>;
indexOf: (searchElement: JsonPatch.JsonPatchOperation, fromIndex?: number) => number;
lastIndexOf: (searchElement: JsonPatch.JsonPatchOperation, fromIndex?: number) => number;
every: { (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: JsonPatch.JsonPatchOperation, index: number, ar…;
some: (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => void, thisArg?: any) => void;
map: (callbackfn: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => value is S, thisArg?: any): Array<S>; (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: Readonl…;
reduce: { (callbackfn: (previousValue: JsonPatch.JsonPatchOperation, currentValue: JsonPatch.JsonPatchOperation, currentIndex: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => JsonPatch.JsonPatchOperation): JsonPatch.JsonPatchOperati…;
reduceRight: { (callbackfn: (previousValue: JsonPatch.JsonPatchOperation, currentValue: JsonPatch.JsonPatchOperation, currentIndex: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => JsonPatch.JsonPatchOperation): JsonPatch.JsonPatchOperati…;
find: { (predicate: (value: JsonPatch.JsonPatchOperation, index: number, obj: ReadonlyArray<JsonPatch.JsonPatchOperation>) => value is S, thisArg?: any): S | undefined; (predicate: (value: JsonPatch.JsonPatchOperation, index: number, obj: Readon…;
findIndex: (predicate: (value: JsonPatch.JsonPatchOperation, index: number, obj: ReadonlyArray<JsonPatch.JsonPatchOperation>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, JsonPatch.JsonPatchOperation]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<JsonPatch.JsonPatchOperation>;
includes: (searchElement: JsonPatch.JsonPatchOperation, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: JsonPatch.JsonPatchOperation, index: number, array: Array<JsonPatch.JsonPatchOperation>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => JsonPatch.JsonPatchOperation | undefined;
findLast: { (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => value is S, thisArg?: any): S | undefined; (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: Re…;
findLastIndex: (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => unknown, thisArg?: any) => number;
toReversed: () => Array<JsonPatch.JsonPatchOperation>;
toSorted: (compareFn?: ((a: JsonPatch.JsonPatchOperation, b: JsonPatch.JsonPatchOperation) => number) | undefined) => Array<JsonPatch.JsonPatchOperation>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<JsonPatch.JsonPatchOperation>): Array<JsonPatch.JsonPatchOperation>; (start: number, deleteCount?: number): Array<JsonPatch.JsonPatchOperation> };
with: (index: number, value: JsonPatch.JsonPatchOperation) => Array<JsonPatch.JsonPatchOperation>;
}
second) => [...first: JsonPatch.JsonPatch(parameter) first: {
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<JsonPatch.JsonPatchOperation>>): Array<JsonPatch.JsonPatchOperation>; (...items: Array<JsonPatch.JsonPatchOperation | ConcatArray<JsonPatch.JsonPatchOperation>>): Array<JsonPatch.JsonPatchOperation> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<JsonPatch.JsonPatchOperation>;
indexOf: (searchElement: JsonPatch.JsonPatchOperation, fromIndex?: number) => number;
lastIndexOf: (searchElement: JsonPatch.JsonPatchOperation, fromIndex?: number) => number;
every: { (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: JsonPatch.JsonPatchOperation, index: number, ar…;
some: (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => void, thisArg?: any) => void;
map: (callbackfn: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => value is S, thisArg?: any): Array<S>; (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: Readonl…;
reduce: { (callbackfn: (previousValue: JsonPatch.JsonPatchOperation, currentValue: JsonPatch.JsonPatchOperation, currentIndex: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => JsonPatch.JsonPatchOperation): JsonPatch.JsonPatchOperati…;
reduceRight: { (callbackfn: (previousValue: JsonPatch.JsonPatchOperation, currentValue: JsonPatch.JsonPatchOperation, currentIndex: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => JsonPatch.JsonPatchOperation): JsonPatch.JsonPatchOperati…;
find: { (predicate: (value: JsonPatch.JsonPatchOperation, index: number, obj: ReadonlyArray<JsonPatch.JsonPatchOperation>) => value is S, thisArg?: any): S | undefined; (predicate: (value: JsonPatch.JsonPatchOperation, index: number, obj: Readon…;
findIndex: (predicate: (value: JsonPatch.JsonPatchOperation, index: number, obj: ReadonlyArray<JsonPatch.JsonPatchOperation>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, JsonPatch.JsonPatchOperation]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<JsonPatch.JsonPatchOperation>;
includes: (searchElement: JsonPatch.JsonPatchOperation, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: JsonPatch.JsonPatchOperation, index: number, array: Array<JsonPatch.JsonPatchOperation>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => JsonPatch.JsonPatchOperation | undefined;
findLast: { (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => value is S, thisArg?: any): S | undefined; (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: Re…;
findLastIndex: (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => unknown, thisArg?: any) => number;
toReversed: () => Array<JsonPatch.JsonPatchOperation>;
toSorted: (compareFn?: ((a: JsonPatch.JsonPatchOperation, b: JsonPatch.JsonPatchOperation) => number) | undefined) => Array<JsonPatch.JsonPatchOperation>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<JsonPatch.JsonPatchOperation>): Array<JsonPatch.JsonPatchOperation>; (start: number, deleteCount?: number): Array<JsonPatch.JsonPatchOperation> };
with: (index: number, value: JsonPatch.JsonPatchOperation) => Array<JsonPatch.JsonPatchOperation>;
}
first, ...second: JsonPatch.JsonPatch(parameter) second: {
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<JsonPatch.JsonPatchOperation>>): Array<JsonPatch.JsonPatchOperation>; (...items: Array<JsonPatch.JsonPatchOperation | ConcatArray<JsonPatch.JsonPatchOperation>>): Array<JsonPatch.JsonPatchOperation> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<JsonPatch.JsonPatchOperation>;
indexOf: (searchElement: JsonPatch.JsonPatchOperation, fromIndex?: number) => number;
lastIndexOf: (searchElement: JsonPatch.JsonPatchOperation, fromIndex?: number) => number;
every: { (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: JsonPatch.JsonPatchOperation, index: number, ar…;
some: (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => void, thisArg?: any) => void;
map: (callbackfn: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => value is S, thisArg?: any): Array<S>; (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: Readonl…;
reduce: { (callbackfn: (previousValue: JsonPatch.JsonPatchOperation, currentValue: JsonPatch.JsonPatchOperation, currentIndex: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => JsonPatch.JsonPatchOperation): JsonPatch.JsonPatchOperati…;
reduceRight: { (callbackfn: (previousValue: JsonPatch.JsonPatchOperation, currentValue: JsonPatch.JsonPatchOperation, currentIndex: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => JsonPatch.JsonPatchOperation): JsonPatch.JsonPatchOperati…;
find: { (predicate: (value: JsonPatch.JsonPatchOperation, index: number, obj: ReadonlyArray<JsonPatch.JsonPatchOperation>) => value is S, thisArg?: any): S | undefined; (predicate: (value: JsonPatch.JsonPatchOperation, index: number, obj: Readon…;
findIndex: (predicate: (value: JsonPatch.JsonPatchOperation, index: number, obj: ReadonlyArray<JsonPatch.JsonPatchOperation>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, JsonPatch.JsonPatchOperation]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<JsonPatch.JsonPatchOperation>;
includes: (searchElement: JsonPatch.JsonPatchOperation, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: JsonPatch.JsonPatchOperation, index: number, array: Array<JsonPatch.JsonPatchOperation>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => JsonPatch.JsonPatchOperation | undefined;
findLast: { (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => value is S, thisArg?: any): S | undefined; (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: Re…;
findLastIndex: (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => unknown, thisArg?: any) => number;
toReversed: () => Array<JsonPatch.JsonPatchOperation>;
toSorted: (compareFn?: ((a: JsonPatch.JsonPatchOperation, b: JsonPatch.JsonPatchOperation) => number) | undefined) => Array<JsonPatch.JsonPatchOperation>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<JsonPatch.JsonPatchOperation>): Array<JsonPatch.JsonPatchOperation>; (start: number, deleteCount?: number): Array<JsonPatch.JsonPatchOperation> };
with: (index: number, value: JsonPatch.JsonPatchOperation) => Array<JsonPatch.JsonPatchOperation>;
}
second],
Differ<T, JsonPatch>.patch(oldValue: T, patch: JsonPatch.JsonPatch): Tpatch: (oldValue: ToldValue, patch: JsonPatch.JsonPatch(parameter) patch: {
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<JsonPatch.JsonPatchOperation>>): Array<JsonPatch.JsonPatchOperation>; (...items: Array<JsonPatch.JsonPatchOperation | ConcatArray<JsonPatch.JsonPatchOperation>>): Array<JsonPatch.JsonPatchOperation> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<JsonPatch.JsonPatchOperation>;
indexOf: (searchElement: JsonPatch.JsonPatchOperation, fromIndex?: number) => number;
lastIndexOf: (searchElement: JsonPatch.JsonPatchOperation, fromIndex?: number) => number;
every: { (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: JsonPatch.JsonPatchOperation, index: number, ar…;
some: (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => void, thisArg?: any) => void;
map: (callbackfn: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => value is S, thisArg?: any): Array<S>; (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: Readonl…;
reduce: { (callbackfn: (previousValue: JsonPatch.JsonPatchOperation, currentValue: JsonPatch.JsonPatchOperation, currentIndex: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => JsonPatch.JsonPatchOperation): JsonPatch.JsonPatchOperati…;
reduceRight: { (callbackfn: (previousValue: JsonPatch.JsonPatchOperation, currentValue: JsonPatch.JsonPatchOperation, currentIndex: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => JsonPatch.JsonPatchOperation): JsonPatch.JsonPatchOperati…;
find: { (predicate: (value: JsonPatch.JsonPatchOperation, index: number, obj: ReadonlyArray<JsonPatch.JsonPatchOperation>) => value is S, thisArg?: any): S | undefined; (predicate: (value: JsonPatch.JsonPatchOperation, index: number, obj: Readon…;
findIndex: (predicate: (value: JsonPatch.JsonPatchOperation, index: number, obj: ReadonlyArray<JsonPatch.JsonPatchOperation>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, JsonPatch.JsonPatchOperation]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<JsonPatch.JsonPatchOperation>;
includes: (searchElement: JsonPatch.JsonPatchOperation, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: JsonPatch.JsonPatchOperation, index: number, array: Array<JsonPatch.JsonPatchOperation>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => JsonPatch.JsonPatchOperation | undefined;
findLast: { (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => value is S, thisArg?: any): S | undefined; (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: Re…;
findLastIndex: (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => unknown, thisArg?: any) => number;
toReversed: () => Array<JsonPatch.JsonPatchOperation>;
toSorted: (compareFn?: ((a: JsonPatch.JsonPatchOperation, b: JsonPatch.JsonPatchOperation) => number) | undefined) => Array<JsonPatch.JsonPatchOperation>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<JsonPatch.JsonPatchOperation>): Array<JsonPatch.JsonPatchOperation>; (start: number, deleteCount?: number): Array<JsonPatch.JsonPatchOperation> };
with: (index: number, value: JsonPatch.JsonPatchOperation) => Array<JsonPatch.JsonPatchOperation>;
}
patch) => {
const const value: Jsonvalue = const get: (
input: T,
options?: SchemaAST.ParseOptions
) => Json
get(oldValue: ToldValue)
const const patched: Jsonpatched = import JsonPatchJsonPatch.function apply(
patch: JsonPatch,
oldValue: Schema.Json
): Schema.Json
Applies a JSON Patch to a JSON document.
When to use
Use to execute patches generated by
get
, transform documents
with manually constructed patches, or process patch operations from external
sources.
Details
Executes patch operations sequentially, so later operations see changes made
by earlier operations. It never mutates the input document; array and object
operations copy the affected containers. An empty patch returns the original
reference, and a root replace (path: "") returns the provided value
directly.
Gotchas
Invalid paths, missing properties, and out-of-bounds array indices throw
errors.
Example (Applying a patch)
import { JsonPatch } from "effect"
const document = { items: [1, 2, 3], total: 6 }
const patch: JsonPatch.JsonPatch = [
{ op: "add", path: "/items/-", value: 4 },
{ op: "replace", path: "/total", value: 10 }
]
const result = JsonPatch.apply(patch, document)
// { items: [1, 2, 3, 4], total: 10 }
apply(patch: JsonPatch.JsonPatch(parameter) patch: {
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<JsonPatch.JsonPatchOperation>>): Array<JsonPatch.JsonPatchOperation>; (...items: Array<JsonPatch.JsonPatchOperation | ConcatArray<JsonPatch.JsonPatchOperation>>): Array<JsonPatch.JsonPatchOperation> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<JsonPatch.JsonPatchOperation>;
indexOf: (searchElement: JsonPatch.JsonPatchOperation, fromIndex?: number) => number;
lastIndexOf: (searchElement: JsonPatch.JsonPatchOperation, fromIndex?: number) => number;
every: { (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: JsonPatch.JsonPatchOperation, index: number, ar…;
some: (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => void, thisArg?: any) => void;
map: (callbackfn: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => value is S, thisArg?: any): Array<S>; (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: Readonl…;
reduce: { (callbackfn: (previousValue: JsonPatch.JsonPatchOperation, currentValue: JsonPatch.JsonPatchOperation, currentIndex: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => JsonPatch.JsonPatchOperation): JsonPatch.JsonPatchOperati…;
reduceRight: { (callbackfn: (previousValue: JsonPatch.JsonPatchOperation, currentValue: JsonPatch.JsonPatchOperation, currentIndex: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => JsonPatch.JsonPatchOperation): JsonPatch.JsonPatchOperati…;
find: { (predicate: (value: JsonPatch.JsonPatchOperation, index: number, obj: ReadonlyArray<JsonPatch.JsonPatchOperation>) => value is S, thisArg?: any): S | undefined; (predicate: (value: JsonPatch.JsonPatchOperation, index: number, obj: Readon…;
findIndex: (predicate: (value: JsonPatch.JsonPatchOperation, index: number, obj: ReadonlyArray<JsonPatch.JsonPatchOperation>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, JsonPatch.JsonPatchOperation]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<JsonPatch.JsonPatchOperation>;
includes: (searchElement: JsonPatch.JsonPatchOperation, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: JsonPatch.JsonPatchOperation, index: number, array: Array<JsonPatch.JsonPatchOperation>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => JsonPatch.JsonPatchOperation | undefined;
findLast: { (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => value is S, thisArg?: any): S | undefined; (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: Re…;
findLastIndex: (predicate: (value: JsonPatch.JsonPatchOperation, index: number, array: ReadonlyArray<JsonPatch.JsonPatchOperation>) => unknown, thisArg?: any) => number;
toReversed: () => Array<JsonPatch.JsonPatchOperation>;
toSorted: (compareFn?: ((a: JsonPatch.JsonPatchOperation, b: JsonPatch.JsonPatchOperation) => number) | undefined) => Array<JsonPatch.JsonPatchOperation>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<JsonPatch.JsonPatchOperation>): Array<JsonPatch.JsonPatchOperation>; (start: number, deleteCount?: number): Array<JsonPatch.JsonPatchOperation> };
with: (index: number, value: JsonPatch.JsonPatchOperation) => Array<JsonPatch.JsonPatchOperation>;
}
patch, const value: Jsonvalue)
return var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.is(value1: any, value2: any): booleanReturns true if the values are the same value, false otherwise.
is(const patched: Jsonpatched, const value: Jsonvalue) ? oldValue: ToldValue : const set: (
input: Json,
options?: SchemaAST.ParseOptions
) => T
set(const patched: Jsonpatched)
}
}
}