The jsonpatch
command applies RFC 6902 JSON Patches to JSON or YAML documents.
Install the latest with go get -u github.com/nicksnyder/jsonpatch
.
document1.json
{
"a": 1
}
document2.json
{
"b": 2
}
patch.json
[{ "op": "add", "path": "/c", "value": 3 }]
Running jsonpatch
$ jsonpatch patch.json document1.json document2.json
$ cat document1.json
{
"a": 1,
"c": 3
}
$ cat document2.json
{
"b": 2,
"c": 3
}
document1.json
{
"a": 1
}
document2.json
{
"b": 2
}
batch.json
[
{
"glob": "document1*",
"jsonPatch": [{ "op": "add", "path": "/c", "value": 3 }]
},
{
"glob": "document2*",
"jsonPatch": [{ "op": "add", "path": "/d", "value": 4 }]
}
]
Running jsonpatch
$ jsonpatch batch.json
$ cat document1.json
{
"a": 1,
"c": 3
}
$ cat document2.json
{
"b": 2,
"c": 4
}