func (t *Template) UnmarshalJSON(data []byte) error {
raw := string(data)
data = []byte(strings.ReplaceAll(raw, `"category_info": []`, `"category_info": null`))
type template Template
if err := json.Unmarshal(data, (*template)(t)); err != nil {
return err
}
return nil
}
func (t *Template) UnmarshalJSON(data []byte) error {
raw := string(data)
data = []byte(strings.ReplaceAll(raw, `"category_info": []`, `"category_info": null`))
type template Template
if err := json.Unmarshal(data, (*template)(t)); err != nil {
return err
}
return nil
}
{
"name": "Мой шаблон",
"category_info": {
"id": 109,
"name": "Тест",
}
}
{
"name": "Мой шаблон без категории",
"category_info": []
}