jsonpatch

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2016 License: BSD-3-Clause, Apache-2.0 Imports: 6 Imported by: 0

README

JSON-Patch

Provides the abiilty to modify and test a JSON according to a RFC6902 JSON patch and RFC7386 JSON Merge Patch.

Version: 1.0

GoDoc

Build Status

API Usage

  • Given a []byte, obtain a Patch object

    obj, err := jsonpatch.DecodePatch(patch)

  • Apply the patch and get a new document back

    out, err := obj.Apply(doc)

  • Create a JSON Merge Patch document based on two json documents (a to b):

    mergeDoc, err := jsonpatch.CreateMergePatch(a, b)

  • Bonus API: compare documents for structural equality

    jsonpatch.Equal(doca, docb)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateMergePatch

func CreateMergePatch(a, b []byte) ([]byte, error)

CreateMergePatch creates a merge patch as specified in http://tools.ietf.org/html/draft-ietf-appsawg-json-merge-patch-07

'a' is original, 'b' is the modified document. Both are to be given as json encoded content. The function will return a mergeable json document with differences from a to b.

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

func Equal

func Equal(a, b []byte) bool

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

func MergePatch

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

MergePatch merges the patchData into the docData.

Types

type Patch

type Patch []operation

Patch is an ordered collection of operations.

func DecodePatch

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

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

func (Patch) Apply

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

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

Jump to

Keyboard shortcuts

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