JSON diff library and simple CLI in Go. It can diff two arbitrary complex JSON files if they starts as an json object.
git clone https://github.com/vyskocilm/jf
cd jf
go test
go build github.com/vyskocilm/jf/cmd/jf
./jf testdata/a.json testdata/b.json
bool true false
ints[2] 1 99
number 42 43
string "hello" "hellp"
strings[1] "world" "worle"Warning: depends on reflect and gihub.com/stretchr/objx and both CAN
panic in some circumstances. Package jf type checks everything before use,
so it uses methods like value.MustInt(). However it panics itself if code ends
in an impossible (or not yet implemented one) situation. For example if
diffing code finds a weird type of interface{}, like Go channel or a pointer.
Those can't be passed in JSON.
In any case. Panic of jf is always a sign of a bug or missing feature, so do
not forget to create an issue on GitHub
if you will find one.
- compare primitive values, ints, floats, bools and strings
- allows a specification of float equality function (can be used for int/float coercion)
- compare arrays and maps
- null coerce for A/B or both jsons
- ignore certain keys
- basic cmdline tool
- ignore order of arrays
- API docs
- flags for cmdline tool (those starting by
x-are temporary only and will be dropped) - custom comparator on objx.Value/objx.Value or string???
{
"number": 42,
"string": "hello",
"strings": ["hello", "world"],
"ints": [4, 2, 1]
}
------------------------------
{
"number": 43,
"string": "hellp",
"strings": ["hello", "worle"],
"ints": [4, 2, 99]
}
------------------------------
ints[2] 1 99
number 42 43
string "hello" "hellp"
strings[1] "world" "worle"
{
"key": {
"subkey": {
"id": 11,
"name": "joe"
}
}
}
------------------------------
{
"key": {
"subkey": {
"id": 11,
"name": "Joe"
}
}
}
------------------------------
key.subkey.name "joe" "Joe"
See jsondiff_test.go for more examples.