-
-
Save jpukg/ae7a36709604f738315b5fa49ee7a449 to your computer and use it in GitHub Desktop.
map.vs.structs.mapjson.go
This file contains 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 main | |
import ( | |
"encoding/json" | |
"fmt" | |
) | |
func main() { | |
// Create a map to parse the JSON | |
var data map[string]interface{} | |
// Define a JSON string | |
j := `{"name":"example","numbers":[1,2,3,4],"nested":{"isit":true,"description":"a nested json"}}` | |
// Parse our JSON string | |
err := json.Unmarshal([]byte(j), &data) | |
if err != nil { | |
fmt.Printf("Error parsing JSON string - %s", err) | |
} | |
// Print out one of our JSON values | |
fmt.Printf("Name is %s", data["name"].(string)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment