Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cside/jsondiff
Reports differences between two JSONs.
https://github.com/cside/jsondiff
diff golang json
Last synced: 2 months ago
JSON representation
Reports differences between two JSONs.
- Host: GitHub
- URL: https://github.com/cside/jsondiff
- Owner: Cside
- License: mit
- Created: 2018-01-26T07:50:43.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-02-02T09:59:19.000Z (almost 2 years ago)
- Last Synced: 2024-06-21T05:29:51.679Z (7 months ago)
- Topics: diff, golang, json
- Language: Go
- Homepage:
- Size: 995 KB
- Stars: 10
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jsondiff [![wercker status](https://app.wercker.com/status/cf6fb86dc49eadcac25f466f8df9d05b/s/master "wercker status")](https://app.wercker.com/project/byKey/cf6fb86dc49eadcac25f466f8df9d05b) [![GoDoc](https://godoc.org/github.com/Cside/jsondiff?status.svg)](http://godoc.org/github.com/Cside/jsondiff)
Reports differences between two JSONs
## Example
```go
import (
"testing"
"github.com/Cside/jsondiff"
)a := []byte(`{ "foo":1, "bar":2 }`)
b := []byte(`{ "foo":1, "bar":3 }`)if diff := jsondiff.Diff(a, b); diff != "" {
t.Errorf("two jsons are not equal. diff:\n%s", diff)
}
```output:
```
=== RUN TestMain
--- FAIL: TestMain (0.00s)
main_test.go:14: two jsons are not equal. diff:
{
- "bar": 2,
+ "bar": 3,
"foo": 1
}
FAIL
exit status 1
```## Ignore values
You can ignore some values with specifiying `diffopts.IgnorePath(paths []string)` option.
Target values can be specified with [JSON Pointer](https://tools.ietf.org/html/rfc6901) .
The following test passes.
```go
import (
"testing"
"github.com/Cside/jsondiff"
"github.com/Cside/jsondiff/diffopts"
)a := []byte(`{ "foo": 1, "createdAt": 1517141881 }`)
b := []byte(`{ "foo": 1, "createdAt": 1528845681 }`)if diff := jsondiff.Diff(a, b, diffopts.IgnorePaths([]string{"/createdAt"})); diff != "" {
t.Errorf("two jsons are not equal. diff:\n%s", diff)
}
```## License
[The MIT License](/LICENSE).