Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyPatch ¶
ApplyPatch applies a series of JSON Patch operations to the original JSON-like object (struct or map). It returns the patched document as a map[string]any. The implementation applies operations sequentially and returns an error on the first failing operation.
func ApplyPatchAndHydrate ¶
ApplyPatchAndHydrate applies patches to `original` and unmarshals the resulting document into `updated` (which should be a pointer). This is a convenience for applying patches and then hydrating a typed value.
Types ¶
type Patch ¶
type Patch struct {
Op string `json:"op"`
Path string `json:"path"`
From string `json:"from,omitempty"`
Value any `json:"value,omitempty"`
}
Patch represents a single JSON Patch operation as defined by RFC 6902. The Op field is the operation (add, remove, replace, move). Path is the JSON Pointer location. From is used by move operations and Value holds the operation payload when applicable.
func GeneratePatch ¶
GeneratePatch computes a list of JSON Patch operations that transform the `before` document into the `after` document. Both inputs may be structs or maps; basePath should be the JSON Pointer prefix (e.g. "" or "/root").
The function attempts to produce minimal patches for arrays using an LCS-based algorithm and treats string equality with trimmed whitespace.