I want a json output to look like whats shown below.Notice that based on the parameter type like document or text, the next key changes to document or text.
"components": [
{
"type" : "header",
"parameters": [
{
"type": "document",
"document": {
"filename":"dummy.pdf",
"link": "https://en.unesco.org/inclusivepolicylab/sites/default/files/dummy-pdf_2.pdf"
}
}
]
},
{
"type" : "body",
"parameters": [
{
"type": "text",
"text": "replacement_text"
}
]
}
]
This are my struct definitions:
type Component struct {
Type string `json:"type,omitempty"`
Parameters []Parameter `json:"parameters,omitempty"`
}
type Parameter struct {
Type string `json:"type,omitempty"`
TypeInformation map[string]interface{}
}
When i encode it it comes like this:
"components": [
{
"type": "body",
"parameters": [
{
"type": "text",
"TypeInformation": {
"text": "Param1"
}
},
{
"type": "text",
"TypeInformation": {
"text": "param2"
}
}
]
},
{
"type": "header",
"parameters": [
{
"type": "document",
"TypeInformation": {
"document": {
"link": "http://link",
"filename": "dummy.pdf"
}
}
}
]
}
]
I dont want the TypeInformation key to come in the json, I just want the inner object. How can I do this?