As per http://jsonpatch.com/ JSON Patch is specified in RFC 6902 from the IETF.
Go
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore Initial commit Apr 17, 2015
LICENSE Initial commit Apr 17, 2015
README.md Update README.md Apr 17, 2015
jsonpatch.go encode keys (support rfc6901#section-4) Oct 1, 2017
jsonpatch_complex_test.go more tests Oct 12, 2015
jsonpatch_geojson_test.go implemented tests and fix for geojson coordinates type mismatch Jun 27, 2017
jsonpatch_hypercomplex_test.go
jsonpatch_json_test.go
jsonpatch_simple_test.go make array comparison faster Jul 27, 2017
jsonpatch_supercomplex_test.go

README.md

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/mattbaird/jsonpatch

I tried some of the other "jsonpatch" go implementations, but none of them could diff two json documents and generate format like jsonpatch.com specifies. Here's an example of the patch format:

[
  { "op": "replace", "path": "/baz", "value": "boo" },
  { "op": "add", "path": "/hello", "value": ["world"] },
  { "op": "remove", "path": "/foo"}
]

The API is super simple #example

package main

import (
	"fmt"
	"github.com/mattbaird/jsonpatch"
)

var simpleA = `{"a":100, "b":200, "c":"hello"}`
var simpleB = `{"a":100, "b":200, "c":"goodbye"}`

func main() {
	patch, e := jsonpatch.CreatePatch([]byte(simpleA), []byte(simpleA))
	if e != nil {
		fmt.Printf("Error creating JSON patch:%v", e)
		return
	}
	for _, operation := range patch {
		fmt.Printf("%s\n", operation.Json())
	}
}

This code needs more tests, as it's a highly recursive, type-fiddly monster. It's not a lot of code, but it has to deal with a lot of complexity.