Open kuznet1 opened 7 years ago
Thanks for the report. I'll take a look into the issue.
It looks like it's because the Compare()
function assumes that the outer layer of the JSON is an object, not an array. The function.
As an easy workaround for now, you can always wrap the actual object in another object.
Example: {"_": expectedData }
vs {"_": actualData }
.
Working on the fix_15 branch.
it cannot properly unmarshall this too: {["this is valid json"]}
maybe, this way is help to you:
func AnyJsonDiff(left interface{}, right interface{}) (gojsondiff.Diff, error) {
type Container struct {
Payload any
}
leftBs, err := json.Marshal(Container{left})
if err != nil {
return nil, err
}
rightBs, err := json.Marshal(Container{right})
if err != nil {
return nil, err
}
return gojsondiff.New().Compare(leftBs, rightBs)
}