Skip to content

Instantly share code, notes, and snippets.

@bradclawsie
Created Mar 24, 2012
Embed
What would you like to do?
match Go type to json
#!/usr/bin/env gorun
package main
import (
"encoding/json"
"fmt"
)
type MyJSONType struct {
A int
B string
}
func main() {
s := "{\"A\":123,\"B\":\"hello\"}"
var mjt MyJSONType
um_err := json.Unmarshal([]byte(s),&mjt)
if um_err == nil {
fmt.Printf("%v\n",mjt)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment