1# yaml-patch 2 3`yaml-patch` is a version of Evan Phoenix's 4[json-patch](https://github.com/evanphx/json-patch), which is an implementation 5of [JavaScript Object Notation (JSON) Patch](https://tools.ietf.org/html/rfc6902), 6but for YAML. 7 8 9## Installing 10 11`go get github.com/krishicks/yaml-patch` 12 13If you want to use the CLI: 14 15`go get github.com/krishicks/yaml-patch/cmd/yaml-patch` 16 17## API 18 19Given the following RFC6902-ish YAML document, `ops`: 20 21``` 22--- 23- op: add 24 path: /baz/waldo 25 value: fred 26``` 27 28And the following YAML that is to be modified, `src`: 29 30``` 31--- 32foo: bar 33baz: 34 quux: grault 35``` 36 37Decode the ops file into a patch: 38 39``` 40patch, err := yamlpatch.DecodePatch(ops) 41// handle err 42``` 43 44Then apply that patch to the document: 45 46``` 47dst, err := patch.Apply(src) 48// handle err 49 50// do something with dst 51``` 52 53### Example 54 55``` 56doc := []byte(`--- 57foo: bar 58baz: 59 quux: grault 60`) 61 62ops := []byte(`--- 63- op: add 64 path: /baz/waldo 65 value: fred 66`) 67 68patch, err := yamlpatch.DecodePatch(ops) 69if err != nil { 70 log.Fatalf("decoding patch failed: %s", err) 71} 72 73bs, err := patch.Apply(doc) 74if err != nil { 75 log.Fatalf("applying patch failed: %s", err) 76} 77 78fmt.Println(string(bs)) 79``` 80 81``` 82baz: 83 quux: grault 84 waldo: fred 85foo: bar 86``` 87