json-patch: github.com/evanphx/json-patch Index | Files | Directories

package jsonpatch

import "github.com/evanphx/json-patch"

Index

Package Files

errors.go merge.go patch.go

Variables

var (
    // SupportNegativeIndices decides whether to support non-standard practice of
    // allowing negative indices to mean indices starting at the end of an array.
    // Default to true.
    SupportNegativeIndices bool = true
    // AccumulatedCopySizeLimit limits the total size increase in bytes caused by
    // "copy" operations in a patch.
    AccumulatedCopySizeLimit int64 = 0
)
var (
    ErrTestFailed   = errors.New("test failed")
    ErrMissing      = errors.New("missing value")
    ErrUnknownType  = errors.New("unknown object type")
    ErrInvalid      = errors.New("invalid state detected")
    ErrInvalidIndex = errors.New("invalid index referenced")
)

func CreateMergePatch Uses

func CreateMergePatch(originalJSON, modifiedJSON []byte) ([]byte, error)

CreateMergePatch will return a merge patch document capable of converting the original document(s) to the modified document(s). The parameters can be bytes of either two JSON Documents, or two arrays of JSON documents. The merge patch returned follows the specification defined at http://tools.ietf.org/html/draft-ietf-appsawg-json-merge-patch-07

func Equal Uses

func Equal(a, b []byte) bool

Equal indicates if 2 JSON documents have the same structural equality.

func MergeMergePatches Uses

func MergeMergePatches(patch1Data, patch2Data []byte) ([]byte, error)

MergeMergePatches merges two merge patches together, such that applying this resulting merged merge patch to a document yields the same as merging each merge patch to the document in succession.

func MergePatch Uses

func MergePatch(docData, patchData []byte) ([]byte, error)

MergePatch merges the patchData into the docData.

type AccumulatedCopySizeError Uses

type AccumulatedCopySizeError struct {
    // contains filtered or unexported fields
}

AccumulatedCopySizeError is an error type returned when the accumulated size increase caused by copy operations in a patch operation has exceeded the limit.

func NewAccumulatedCopySizeError Uses

func NewAccumulatedCopySizeError(l, a int64) *AccumulatedCopySizeError

NewAccumulatedCopySizeError returns an AccumulatedCopySizeError.

func (*AccumulatedCopySizeError) Error Uses

func (a *AccumulatedCopySizeError) Error() string

Error implements the error interface.

type ArraySizeError Uses

type ArraySizeError struct {
    // contains filtered or unexported fields
}

ArraySizeError is an error type returned when the array size has exceeded the limit.

func NewArraySizeError Uses

func NewArraySizeError(l, s int) *ArraySizeError

NewArraySizeError returns an ArraySizeError.

func (*ArraySizeError) Error Uses

func (a *ArraySizeError) Error() string

Error implements the error interface.

type Operation Uses

type Operation map[string]*json.RawMessage

Operation is a single JSON-Patch step, such as a single 'add' operation.

func (Operation) From Uses

func (o Operation) From() (string, error)

From reads the "from" field of the Operation.

func (Operation) Kind Uses

func (o Operation) Kind() string

Kind reads the "op" field of the Operation.

func (Operation) Path Uses

func (o Operation) Path() (string, error)

Path reads the "path" field of the Operation.

func (Operation) ValueInterface Uses

func (o Operation) ValueInterface() (interface{}, error)

ValueInterface decodes the operation value into an interface.

type Patch Uses

type Patch []Operation

Patch is an ordered collection of Operations.

func DecodePatch Uses

func DecodePatch(buf []byte) (Patch, error)

DecodePatch decodes the passed JSON document as an RFC 6902 patch.

func (Patch) Apply Uses

func (p Patch) Apply(doc []byte) ([]byte, error)

Apply mutates a JSON document according to the patch, and returns the new document.

func (Patch) ApplyIndent Uses

func (p Patch) ApplyIndent(doc []byte, indent string) ([]byte, error)

ApplyIndent mutates a JSON document according to the patch, and returns the new document indented.

Directories

PathSynopsis
cmd/json-patch
v5

Package jsonpatch imports 7 packages (graph) and is imported by 732 packages. Updated 2020-08-12. Refresh now. Tools for package owners.