Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ntbosscher/jsondiff
https://github.com/ntbosscher/jsondiff
Last synced: 26 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/ntbosscher/jsondiff
- Owner: ntbosscher
- Created: 2020-11-25T18:33:44.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-07-26T12:55:00.000Z (over 1 year ago)
- Last Synced: 2024-06-20T19:23:32.711Z (7 months ago)
- Language: Go
- Size: 9.77 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# JSONDiff
Compares oldValue with newValue and returns a json tree of the changed values.
## Installation
```
go get -u github.com/ntbosscher/jsondiff
```## Details
[godoc.org/github.com/ntbosscher/jsondiff](https://godoc.org/github.com/ntbosscher/jsondiff)
```go
func Example() {
A := &ExampleEntity{
ID: 1,
Name: "John",
List: []int{3,2,1},
Relation: &ExampleEntity{
ID: 3,
Name: "Ken",
},
}B := &ExampleEntity{
ID: 2,
Name: "John",
List: []int{1,2,3},
Relation: &ExampleEntity{
ID: 2,
Name: "asdf",
},
}diff, _ := Diff(a, b)
fmt.Println(string(diff))
// Output: {"ID":2,"Relation":{"ID":2,"Name":"asdf"}}diff, _ := DiffOldNew(A, B)
fmt.Println(string(diff))
// Output: {"ID":{"New":2,"Old":1},"List":{"New":[1,2,3],"Old":[3,2,1]},"Relation":{"ID":{"New":2,"Old":3},"Name":{"New":"asdf","Old":"Ken"}}}diff, _ := DiffFormat(A, B, OldValueFormat)
fmt.Println(string(diff))
// Output: {"ID":1,"List":[3,2,1],"Relation":{"ID":3,"Name":"Ken"}}
}
```