Skip to content
/ jf Public

Json difF: Go library and CLI printing diffs of two json files

License

Notifications You must be signed in to change notification settings

vyskocilm/jf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CircleCI license

jf: Json difF

JSON diff library and simple CLI in Go. It can diff two arbitrary complex JSON files if they starts as an json object.

Installation and usage

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.

Features

  1. compare primitive values, ints, floats, bools and strings
  2. allows a specification of float equality function (can be used for int/float coercion)
  3. compare arrays and maps
  4. null coerce for A/B or both jsons
  5. ignore certain keys
  6. basic cmdline tool
  7. ignore order of arrays

TODO

  1. API docs
  2. flags for cmdline tool (those starting by x- are temporary only and will be dropped)
  3. custom comparator on objx.Value/objx.Value or string???

Simple values

{
 "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"

Nested maps

{
 "key": {
  "subkey": {
   "id": 11,
   "name": "joe"
  }
 }
}
------------------------------
{
 "key": {
  "subkey": {
   "id": 11,
   "name": "Joe"
  }
 }
}
------------------------------
key.subkey.name "joe" "Joe"

See jsondiff_test.go for more examples.

About

Json difF: Go library and CLI printing diffs of two json files

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages