Created
November 26, 2020 17:27
-
-
Save madflojo/fa1c3a3727d8b0f69e97f2839fcfa53c to your computer and use it in GitHub Desktop.
map.vs.structs.mapjson.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
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