如何为嵌套在struct中的接口在同一级别显示json?

Here has an interface SpecificTemplate nested inside struct Template:

package main

import (
   "encoding/json"
   "fmt"
)

type SpecificTemplate interface {
    GetLabel() string
}

type TemplateA struct {
    Label string `json:"label"`
}

func (t TemplateA) GetLabel() string {
    return t.Label
}

type Template struct {
    Id int64 `json:"id"`
    SpecificTemplate
}

func main() {
    ta := TemplateA{
        Label: `label1`,
    }
    t := Template{
       Id:               1,
       SpecificTemplate: ta,
    }

    data, _ := json.Marshal(t)
    fmt.Println(string(data))
}

It would be

{
    "id":1,
    "SpecificTemplate":{
        "label":"label1"
    }
}

I wanna kown how to show json at same level, just like:

{
    "id":1,
    "label":"label1"
}

It kinda depends on the level of complexity you wanna reach...

If you want to expose only the label I should advice you to create a MarshalJSON function, just like this...

func (t Template) MarshalJSON() ([]byte, error) {
    return json.Marshal(&struct {
        Id int64 `json:"id"`
        Label string `json:"label"`
    }{
        Id: t.Id,
        Label: t.SpecificTemplate.GetLabel(),
    })
}

With this your json.Marshal(t) will call this function and you will receive a flattened json...

However if you want to expose more Fields from the template you should use reflection, as pointed out by Iain Duncan in his comment