Skip to content

Instantly share code, notes, and snippets.

@danmrichards
Created March 21, 2017 10:41
Show Gist options
  • Save danmrichards/cb48e3ecde8558b8304370dc215374c2 to your computer and use it in GitHub Desktop.
Save danmrichards/cb48e3ecde8558b8304370dc215374c2 to your computer and use it in GitHub Desktop.
Compare the equality of 2 JSON byte arrays
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