Created
October 20, 2013 01:31
-
-
Save asmedrano/7063785 to your computer and use it in GitHub Desktop.
My simplified version of python's json.loads in Go
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
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