jsonpatch

package module
v0.0.0-...-c895b20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2026 License: Apache-2.0 Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

jsonpatch

As per http://jsonpatch.com/ JSON Patch is specified in RFC 6902 from the IETF.

JSON Patch allows you to generate JSON that describes changes you want to make to a document, so you don't have to send the whole doc. JSON Patch format is supported by HTTP PATCH method, allowing for standards based partial updates via REST APIs.

go get github.com/platform-engineering-labs/jsonpatch

TODO: describe what this jsonpatch library does different than the one we forked

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByPath

type ByPath []JsonPatchOperation

func (ByPath) Len

func (a ByPath) Len() int

func (ByPath) Less

func (a ByPath) Less(i, j int) bool

func (ByPath) Swap

func (a ByPath) Swap(i, j int)

type CoOwned

type CoOwned map[Path]Drainable

CoOwned restricts removals per path: on a co-owned path only members whose identity is in the path's Drainable set may be removed; every other surplus member is tolerated (no op of any kind). A path absent from the map is not co-owned. An empty Drainable tolerates everything.

type Collections

type Collections struct {
	EntitySets EntitySets
	Arrays     []Path
	Atomics    []Path
	CoOwned    CoOwned
}

type Drainable

type Drainable map[string]struct{}

Drainable is the set of member identities remove operations may target on a co-owned path. Identity encoding is the caller's: for a plain set listing the canonical JSON of the element (the same encoding processSet keys on), for an entity set the JSON-marshaled index-field value, for an object path the raw key string.

type EntitySets

type EntitySets map[Path]Key

func (EntitySets) Add

func (s EntitySets) Add(path Path, key Key)

func (EntitySets) Get

func (s EntitySets) Get(path Path) (Key, bool)

type JsonPatchOperation

type JsonPatchOperation struct {
	Operation string `json:"op"`
	Path      string `json:"path"`
	Value     any    `json:"value,omitempty"`
}

func CreatePatch

func CreatePatch(a, b []byte, collections Collections, ignoredFields []Path, strategy PatchStrategy) ([]JsonPatchOperation, error)

CreatePatch creates a patch as specified in http://jsonpatch.com/

'a' is original, 'b' is the modified document. Both are to be given as json encoded content. The function will return an array of JsonPatchOperations If ignoreArrayOrder is true, arrays with the same elements but in different order will be considered equal

An e rror will be returned if any of the two documents are invalid.

func NewPatch

func NewPatch(operation, path string, value any) JsonPatchOperation

func (*JsonPatchOperation) Json

func (j *JsonPatchOperation) Json() string

func (*JsonPatchOperation) MarshalJson

func (j *JsonPatchOperation) MarshalJson() ([]byte, error)

type Key

type Key string

type PatchStrategy

type PatchStrategy string
const (
	PatchStrategyExactMatch   PatchStrategy = "exact-match"
	PatchStrategyEnsureExists PatchStrategy = "ensure-exists"
	PatchStrategyEnsureAbsent PatchStrategy = "ensure-absent"
)

type Path

type Path string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL