Created
December 1, 2017 22:17
-
-
Save miguelmota/0d5f299bac1bfb2defa729bdb08def92 to your computer and use it in GitHub Desktop.
golang check if is equal json string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"encoding/json" | |
"reflect" | |
) | |
func IsEqualJson(s1, s2 string) (bool, error) { | |
var o1 interface{} | |
var o2 interface{} | |
err := json.Unmarshal([]byte(s1), &o1) | |
if err != nil { | |
return false, err | |
} | |
err = json.Unmarshal([]byte(s1), &o2) | |
if err != nil { | |
return false, err | |
} | |
return reflect.DeepEqual(o1, o2), nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment