gojson
gojson copied to clipboard
Define types for array elements
This came up in https://github.com/ChimeraCoder/anaconda/pull/187.
[
{
"id": "1",
"url": "https://united.fr/webhook",
"valid": true,
"created_timestamp": "134325325301"
}
]
will create
type Foo []struct {
CreatedTimestamp string `json:"created_timestamp"`
ID string `json:"id"`
URL string `json:"url"`
Valid bool `json:"valid"`
}
but in reality, most of the time, this is more convenient:
type Foo struct {
CreatedTimestamp string `json:"created_timestamp"`
ID string `json:"id"`
URL string `json:"url"`
Valid bool `json:"valid"`
}