Created
October 3, 2018 14:05
-
-
Save ilyabrin/6c108a7178946837f2fa5f5fecea5be2 to your computer and use it in GitHub Desktop.
JSON from nested map
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() { | |
var data = map[string]map[string]string{ | |
"public_key": map[string]string{}, | |
"custom_properties": map[string]string{}, | |
} | |
data["public_key"]["name"] = "x" | |
data["custom_properties"]["key1"] = "value1" | |
data["custom_properties"]["key2"] = "value2" | |
js, _ := json.MarshalIndent(data, " ", " ") | |
fmt.Println(string(js)) | |
} | |
/* | |
{ | |
"custom_properties": { | |
"key1": "value1", | |
"key2": "value2" | |
}, | |
"public_key": { | |
"name": "x" | |
} | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment