Skip to content

Instantly share code, notes, and snippets.

@asmedrano
Created October 20, 2013 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asmedrano/7063785 to your computer and use it in GitHub Desktop.
Save asmedrano/7063785 to your computer and use it in GitHub Desktop.
My simplified version of python's json.loads in Go
func jsonLoads(j string) map[string]interface{} {
sB := []byte(j)
var f interface{}
// At this point the Go value in f would be a map whose keys are strings and whose values are themselves stored as empty interface values:
// If the json is formated wrong, f will be nil :TODO catch that error
json.Unmarshal(sB, &f)
// To access this data we can use a type assertion to access `f`'s underlying map[string]interface{}:
m := f.(map[string]interface{})
return m
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment