Skip to content

Instantly share code, notes, and snippets.

@ilyabrin
Created October 3, 2018 14:05
Show Gist options
  • Save ilyabrin/6c108a7178946837f2fa5f5fecea5be2 to your computer and use it in GitHub Desktop.
Save ilyabrin/6c108a7178946837f2fa5f5fecea5be2 to your computer and use it in GitHub Desktop.
JSON from nested map
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