JSON进行结构

I have a JSON like

{
    "company_id": "Sahil",
    "company_name": "Sahil",
    "ats_operators": ["123"],
    "ids": [
        {
            "duns_id": "1234"
        }
        ],
        "company_symbol": "1234"
}

I wanted to convert the above JSON into the Go Structure.

I have one way to do it like:

type AutoGenerated struct {
    CompanyID    string   `json:"company_id"`
    CompanyName  string   `json:"company_name"`
    AtsOperators []string `json:"ats_operators"`
    Ids          []struct {
        DubnsID string `json:"dubns_id"`
    } `json:"ids"`
    CompanySymbol string `json:"company_symbol"`
}

But i wanted to use the Go-Map instead of Nested structure.

I tried to use the below code but it is unable to parse the above JSON.

type Test struct {
    CompanyID     string              `json:"company_id"`
    CompanyName   string              `json:"company_name"`
    CompanySymbol string              `json:"company_symbol"`
    IDs           map[string][]string `json:"ids"`
    AtsOperators  []string            `json:"ats_operators"`
}

Please help and let me know what is the wrong with the above Go structure?

You might have to use a struct like this:

type AutoGenerated struct {
    CompanyID     string                   `json:"company_id"`
    CompanyName   string                   `json:"company_name"`
    AtsOperators  []string                 `json:"ats_operators"`
    Ids           []map[string]interface{} `json:"ids"`
    CompanySymbol string                   `json:"company_symbol"`
}

Do something like this and try. If you are fetching the data from mongodb then keep bson:"" part else just json tags is ok.

type DubnsID struct {
  DubnsId string `bson:"dubns_id" json:"dubns_id"`
}

type AutoGenerated struct {
 CompanyID     string    `bson:"company_id" json:"company_id"`
 CompanyName   string    `bson:"company_name" json:"company_name"`
 AtsOperators  []string  `bson:"ats_operators" json:"ats_operators"`
 Ids           map[string][]DubnsID `bson:"ids" json:"ids"`
 CompanySymbol string    `bson:"company_symbol" json:"company_symbol"`
}