Created
March 21, 2017 10:41
-
-
Save danmrichards/cb48e3ecde8558b8304370dc215374c2 to your computer and use it in GitHub Desktop.
Compare the equality of 2 JSON byte arrays
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
package jsonequals | |
import ( | |
"encoding/json" | |
"log" | |
"reflect" | |
) | |
// jsonEquals - Compare the equality of two JSON byte arrays. | |
// | |
// Params: | |
// jsonA []byte - The first JSON byte array. | |
// jsonB []byte - The second JSON byte array. | |
// | |
// Return: | |
// bool - Are the JSON byte arrays equal. | |
func jsonEquals(jsonA, jsonB []byte) bool { | |
var interfaceA interface{} | |
aErr := json.Unmarshal(jsonA, &interfaceA) | |
if aErr != nil { | |
log.Fatal(aErr) | |
} | |
var interfaceB interface{} | |
bErr := json.Unmarshal(jsonB, &interfaceB) | |
if bErr != nil { | |
log.Fatal(bErr) | |
} | |
return reflect.DeepEqual(interfaceA, interfaceB) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment