I have a data structure like this:
type (
parent struct {
Items []*child
}
child struct {
Field string `json:"field"`
}
)
I also want parent to have methods:
func (p *parent) example() { }
However the json requirement is that parent is just an array:
[
{
"field": "data"
}
]
I want parent to be a simple array, but in order for parent to have methods, it cannot be an array type.
Is there a way to solve both problems with one data structure?
(To make matters more complicated, the actual data structure I have to work with has two levels of this: greatgrandparent contains []grandparent, and grandparent has a parent that contains []child. The json structure is externally defined, the arrays have no key names, and I would like methods on each of the four structs.)