Remove BPA from Makefile
[icn.git] / cmd / bpa-operator / vendor / github.com / appscode / jsonpatch / README.md
1 # jsonpatch
2
3 [![Build Status](https://travis-ci.org/appscode/jsonpatch.svg?branch=master)](https://travis-ci.org/appscode/jsonpatch)
4 [![Go Report Card](https://goreportcard.com/badge/appscode/jsonpatch "Go Report Card")](https://goreportcard.com/report/appscode/jsonpatch)
5 [![GoDoc](https://godoc.org/github.com/appscode/jsonpatch?status.svg "GoDoc")](https://godoc.org/github.com/appscode/jsonpatch)
6
7 As per http://jsonpatch.com JSON Patch is specified in RFC 6902 from the IETF.
8
9 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.
10
11 ```console
12 go get github.com/appscode/jsonpatch
13 ```
14
15 I tried some of the other "jsonpatch" go implementations, but none of them could diff two json documents and 
16 generate format like jsonpatch.com specifies. Here's an example of the patch format:
17
18 ```json
19 [
20   { "op": "replace", "path": "/baz", "value": "boo" },
21   { "op": "add", "path": "/hello", "value": ["world"] },
22   { "op": "remove", "path": "/foo"}
23 ]
24
25 ```
26 The API is super simple
27
28 ## example
29
30 ```go
31 package main
32
33 import (
34         "fmt"
35         "github.com/appscode/jsonpatch"
36 )
37
38 var simpleA = `{"a":100, "b":200, "c":"hello"}`
39 var simpleB = `{"a":100, "b":200, "c":"goodbye"}`
40
41 func main() {
42         patch, e := jsonpatch.CreatePatch([]byte(simpleA), []byte(simpleA))
43         if e != nil {
44                 fmt.Printf("Error creating JSON patch:%v", e)
45                 return
46         }
47         for _, operation := range patch {
48                 fmt.Printf("%s\n", operation.Json())
49         }
50 }
51 ```
52
53 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.