gojson icon indicating copy to clipboard operation
gojson copied to clipboard

Define types for array elements

Open ChimeraCoder opened this issue 7 years ago • 0 comments

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"`
}

ChimeraCoder avatar Jun 18 '17 17:06 ChimeraCoder