type jsonData struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
}
{
"first_name": "first",
"last_name": "last"
}
{
"first_name": "first",
"last_name": "last",
"favorite_color": "orange",
"age": 92
}
type jsonData struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Extras map[string]interface{} `json:",extras"`
}
The json package uses map[string]interface{}
and []interface{}
values to store arbitrary JSON objects and arrays; it will happily unmarshal any valid JSON blob into a plain interface{}
value. The default concrete Go types are:
bool
for JSON booleans,float64
for JSON numbers,string
for JSON strings, andnil
for JSON null.--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/630827e2-8277-4231-9ab1-31881198a386%40googlegroups.com.
const testJSON = `{
"first_name": "first", "last_name": "last", "favorite_color": "orange", "age": 92
}`
func TestUnmarshalling(t *testing.T) { var res struct {
FirstName string `json:"first_name"` LastName string `json:"last_name"` }
err := json.Unmarshal([]byte(testJSON), &res) assert.NoError(t, err) out, err := json.MarshalIndent(&res, "", "\t") assert.NoError(t, err) assert.Equal(t, testJSON, string(out))}
To unsubscribe from this group and stop receiving emails from it, send an email to golan...@googlegroups.com.
Looks like your thoughts are the right ones:
--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/UZri3aWypTI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/376071d9-6852-419b-923c-9d36f46bf158%40googlegroups.com.