Last active
August 29, 2015 14:06
-
-
Save piaoger/17f155c9c46d2856643e to your computer and use it in GitHub Desktop.
json marshal in 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 ( | |
"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