jsonpatch2: github.com/VictorLowther/jsonpatch2 Index | Files | Directories

package jsonpatch2

import "github.com/VictorLowther/jsonpatch2"

Index

Package Files

genpatch.go patch.go pointer.go

Constants

const ContentType = "application/json-patch+json"

type Operation Uses

type Operation struct {
    // Op can be one of:
    //    * "add"
    //    * "remove"
    //    * "replace"
    //    * "move"
    //    * "copy"
    //    * "test"
    // All Operations must have an Op.
    Op  string `json:"op"`
    // Path is a JSON Pointer as defined in RFC 6901
    // All Operations must have a Path
    Path string `json:"path"`
    // From is a JSON pointer indicating where a value should be
    // copied/moved from.  From is only used by copy and move operations.
    From string `json:"from"`
    // Value is the Value to be used for add, replace, and test operations.
    Value interface{} `json:"value"`
    // contains filtered or unexported fields
}

operation represents a valid JSON Patch operation as defined by RFC 6902

func (*Operation) UnmarshalJSON Uses

func (o *Operation) UnmarshalJSON(buf []byte) error

type Patch Uses

type Patch []Operation

Patch is an array of individual JSON Patch operations.

func Generate Uses

func Generate(base, target []byte, paranoid bool) (Patch, error)

Generate generates a JSON Patch that will modify base into target. If paranoid is true, then the generated patch with have test checks for changed item.

base and target must be byte arrays containing valid JSON

func GenerateFull Uses

func GenerateFull(base, target []byte, paranoid, pretest bool) (Patch, error)

Generate generates a JSON Patch that will modify base into target. If paranoid is true, then the generated patch with have test checks for changed item. If pretest is true, then the generated patch with have test ALL parts of the base.

base and target must be byte arrays containing valid JSON

func NewPatch Uses

func NewPatch(buf []byte) (res Patch, err error)

NewPatch takes a byte array and tries to unmarshal it.

func (Patch) Apply Uses

func (p Patch) Apply(base []byte) (result []byte, err error, loc int)

ApplyJSON does the same thing as Apply, except the inputs should be JSON-containing byte arrays instead of unmarshalled JSON

type Pointer Uses

type Pointer []pointerSegment

Pointer is a JSON Pointer

func NewPointer Uses

func NewPointer(s string) (Pointer, error)

newpointer takes a string that conforms to RFC6901 and turns it into a JSON pointer.

func (Pointer) Append Uses

func (p Pointer) Append(frag string) Pointer

func (Pointer) Chop Uses

func (p Pointer) Chop() (string, Pointer)

Chop extracts the last element in the pointer, returning it and the rest of the pointer.

func (Pointer) Contains Uses

func (a Pointer) Contains(b Pointer) bool

Contains tests to see if B is a subset of A

func (Pointer) Copy Uses

func (p Pointer) Copy(from interface{}, at Pointer) (interface{}, error)

Copy deep-copies the value pointed to by p in from to the location pointed to by at.

func (Pointer) Get Uses

func (p Pointer) Get(from interface{}) (interface{}, error)

Get takes an unmarshalled JSON blob, and returns the value pointed at by the pointer. The unmarshalled blob is left unchanged.

func (Pointer) MarshalJSON Uses

func (p Pointer) MarshalJSON() ([]byte, error)

Allow a pointer to be marshalled to valid JSON.

func (Pointer) Move Uses

func (p Pointer) Move(from interface{}, at Pointer) (interface{}, error)

Move moves the value pointed to by p in from to the location pointed to by at.

func (Pointer) Put Uses

func (p Pointer) Put(to interface{}, val interface{}) (interface{}, error)

Put puts val into to at the position indicated by the pointer, returning a possibly new value for to. The position does not have to already exist or refer to a preexisting Value.

Put may have to return a new to if to happens to be a slice, since the semantics of Put necessarily involve growing the Slice.

func (*Pointer) Remove Uses

func (p *Pointer) Remove(from interface{}) (interface{}, error)

Remove removes the value pointed to by the pointer from from, returning a possibly new value for from.

Remove may have to return a new from if it is a slice, because the semantics for Reomve on a Slice involve shrinking it, which involves reallocation the way we do it.

func (Pointer) Replace Uses

func (p Pointer) Replace(to interface{}, val interface{}) (interface{}, error)

Replace replaces the pointed at value (which must exist) with val.

func (Pointer) Shift Uses

func (p Pointer) Shift() (string, Pointer)

Shift extracts the first element in the pointer, returning it and the rest of the pointer.

func (Pointer) String Uses

func (p Pointer) String() string

String takes a pointer and returns its string value.

func (*Pointer) Test Uses

func (p *Pointer) Test(from interface{}, sample interface{}) error

func (*Pointer) UnmarshalJSON Uses

func (p *Pointer) UnmarshalJSON(buf []byte) error

Allow unmarshalling from JSON

Directories

PathSynopsis
utils

Package jsonpatch2 imports 6 packages (graph) and is imported by 12 packages. Updated 2018-06-08. Refresh now. Tools for package owners.