An API endpoint returns a set of posts, and a field attached_image
in each post can come in as one of two types
JSON snippet:
{
"attached_image": { // Empty string if there is no image
"url": "https://cataas.com/c?width=500&height=500",
"width": 500,
"height": 600
},
}
Is there any way to implement it, so that if attached_image
is an empty string, the field would be a string, and otherwise it would become a struct, without checking the type of the value that comes from json.Unmarshal
?