Patchwerk
Go JSON patch
Use Patchwerk to create RFC6902 JSON patches.
At the moment of writing this is the only working Go library for creating JSON patches. If you wish to apply the patches I recommend using evanphx/json-patch (it only allows for applying patches, not generating them).
The project was originally cloned from mattbaird/jsonpatch.
Installation
go get github.com/herkyl/patchwerk
Usage
package main
import (
"fmt"
"github.com/herkyl/patchwerk"
)
func main() {
a := `{"a":100, "b":200}`
b := `{"a":100, "b":200, "c":300}`
patch, err := patchwerk.DiffBytes([]byte(a), []byte(b))
if err != nil {
fmt.Printf("Error creating JSON patch: %v", err)
return
}
fmt.Println(string(patch)) // [{"op": "add", "path": "/c", "value": 300}]
}