Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Created December 1, 2017 22:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miguelmota/0d5f299bac1bfb2defa729bdb08def92 to your computer and use it in GitHub Desktop.
Save miguelmota/0d5f299bac1bfb2defa729bdb08def92 to your computer and use it in GitHub Desktop.
golang check if is equal json string
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