Skip to content

Instantly share code, notes, and snippets.

@piaoger
Last active August 29, 2015 14:06
Show Gist options
  • Save piaoger/17f155c9c46d2856643e to your computer and use it in GitHub Desktop.
Save piaoger/17f155c9c46d2856643e to your computer and use it in GitHub Desktop.
json marshal in go
package main
import (
"fmt"
"encoding/json"
)
type js struct {
A map[string]interface{}
B interface{}
}
func jsonMarshal() ( []byte, error){
j := js{
A: map[string]interface{}{
"key": 3,
"values": map[string]interface{}{
"key1": 3,
"key2": "value",
},
},
B: map[string]interface{}{
"key1": 41,
"key2": "value",
},
}
return json.Marshal(j)
}
func main() {
jss,_ := jsonMarshal()
fmt.Printf("Hello, playground %q", jss)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment