yudai / gojsondiff

Go JSON Diff
Other
535 stars 81 forks source link

provide a common way to diff #51

Open cold-bin opened 4 months ago

cold-bin commented 4 months ago
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)
}