Documentation
¶
Index ¶
- Variables
- func CreateMergePatch(originalJSON, modifiedJSON []byte) ([]byte, error)
- func Equal(a, b []byte) bool
- func MergeMergePatches(patch1Data, patch2Data []byte) ([]byte, error)
- func MergePatch(docData, patchData []byte) ([]byte, error)
- type AccumulatedCopySizeError
- type ApplyOptions
- type ArraySizeError
- type Document
- type Operation
- type Patch
- func (p Patch) Apply(doc []byte) ([]byte, error)
- func (p Patch) ApplyIndent(doc []byte, indent string) ([]byte, error)
- func (p Patch) ApplyIndentWithOptions(doc []byte, indent string, options *ApplyOptions) ([]byte, error)
- func (p Patch) ApplyToDocument(d *Document, opts *ApplyOptions) error
- func (p Patch) ApplyWithOptions(doc []byte, options *ApplyOptions) ([]byte, error)
Constants ¶
This section is empty.
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") ErrExpectedObject = errors.New("invalid value, expected object") )
Functions ¶
func CreateMergePatch ¶
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 MergeMergePatches ¶
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 ¶
MergePatch merges the patchData into the docData.
Types ¶
type AccumulatedCopySizeError ¶
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 ¶
func NewAccumulatedCopySizeError(l, a int64) *AccumulatedCopySizeError
NewAccumulatedCopySizeError returns an AccumulatedCopySizeError.
func (*AccumulatedCopySizeError) Error ¶
func (a *AccumulatedCopySizeError) Error() string
Error implements the error interface.
type ApplyOptions ¶
type ApplyOptions struct {
// 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
// AccumulatedCopySizeLimit limits the total size increase in bytes caused by
// "copy" operations in a patch.
AccumulatedCopySizeLimit int64
// AllowMissingPathOnRemove indicates whether to fail "remove" operations when the target path is missing.
// Default to false.
AllowMissingPathOnRemove bool
// EnsurePathExistsOnAdd instructs json-patch to recursively create the missing parts of path on "add" operation.
// Default to false.
EnsurePathExistsOnAdd bool
EscapeHTML bool
}
ApplyOptions specifies options for calls to ApplyWithOptions. Use NewApplyOptions to obtain default values for ApplyOptions.
func NewApplyOptions ¶
func NewApplyOptions() *ApplyOptions
NewApplyOptions creates a default set of options for calls to ApplyWithOptions.
type ArraySizeError ¶
type ArraySizeError struct {
// contains filtered or unexported fields
}
ArraySizeError is an error type returned when the array size has exceeded the limit.
func NewArraySizeError ¶
func NewArraySizeError(l, s int) *ArraySizeError
NewArraySizeError returns an ArraySizeError.
func (*ArraySizeError) Error ¶
func (a *ArraySizeError) Error() string
Error implements the error interface.
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document is a parsed JSON document that can have multiple Patches applied in sequence without re-parsing or re-marshalling between them.
Typical use is replaying a long history of patches against an accumulating document, where parse+marshal on every Apply call would dominate the cost:
d, err := jsonpatch.ParseDocument(doc, opts)
if err != nil { ... }
for _, p := range patches {
if err := p.ApplyToDocument(d, opts); err != nil { ... }
}
out, err := d.Marshal()
A Document is not safe for concurrent use.
func ParseDocument ¶
func ParseDocument(doc []byte, opts *ApplyOptions) (*Document, error)
ParseDocument parses doc into a reusable Document.
opts is retained for use by Marshal (for EscapeHTML) and as the default for any ApplyToDocument call that passes nil opts. If opts is nil, the defaults from NewApplyOptions are used.
type Operation ¶
type Operation map[string]*json.RawMessage
Operation is a single JSON-Patch step, such as a single 'add' operation.
func (Operation) ValueInterface ¶
ValueInterface decodes the operation value into an interface.
type Patch ¶
type Patch []Operation
Patch is an ordered collection of Operations.
func DecodePatch ¶
DecodePatch decodes the passed JSON document as an RFC 6902 patch.
func (Patch) Apply ¶
Apply mutates a JSON document according to the patch, and returns the new document.
func (Patch) ApplyIndent ¶
ApplyIndent mutates a JSON document according to the patch, and returns the new document indented.
func (Patch) ApplyIndentWithOptions ¶
func (p Patch) ApplyIndentWithOptions(doc []byte, indent string, options *ApplyOptions) ([]byte, error)
ApplyIndentWithOptions mutates a JSON document according to the patch and the passed in ApplyOptions. It returns the new document indented.
func (Patch) ApplyToDocument ¶
func (p Patch) ApplyToDocument(d *Document, opts *ApplyOptions) error
ApplyToDocument applies the patch to an already-parsed Document in place, avoiding the parse/marshal cycle on each call.
Pass nil opts to inherit the options the Document was created with.
func (Patch) ApplyWithOptions ¶
func (p Patch) ApplyWithOptions(doc []byte, options *ApplyOptions) ([]byte, error)
ApplyWithOptions mutates a JSON document according to the patch and the passed in ApplyOptions. It returns the new document.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
json-patch
command
|
|
|
internal
|
|
|
json
Package json implements encoding and decoding of JSON as defined in RFC 7159.
|
Package json implements encoding and decoding of JSON as defined in RFC 7159. |