How to remove top level field name from the output json object but retaining its attributes in golang

I am implementing go API and getting output as json object . I am getting the output as below:

{
    "entityId": "5f1",
    "entries": [
        {
            "Fruit": {
                "name": "1cd9",
                "location": "5f1",
                "ID": "7b9",
                "creationDate": "2019-06-26T18:27:10",
                "lastUpdatedDate": "2019-06-26T18:27:28",
                "startDate": "2019-06-26T08:00:00",
                "endDate": "2019-06-26T08:00:00",
                "entryType": 1
            }
        },
        {
           "Fruit": {
                "name": "1c9",
                "location": "51",
                "ID": "79",
                "creationDate": "2019-06-26T18:27:10",
                "lastUpdatedDate": "2019-06-26T18:27:28",
                "startDate": "2019-06-26T08:00:00",
                "endDate": "2019-06-26T08:00:00",
                "entryType": 1
            },
        }]
}

But, I want output like below:

{
    "entityId": "5f1",
    "entries": [
        {
                "name": "1cd9",
                "location": "5f1",
                "ID": "7b9",
                "creationDate": "2019-06-26T18:27:10",
                "lastUpdatedDate": "2019-06-26T18:27:28",
                "startDate": "2019-06-26T08:00:00",
                "endDate": "2019-06-26T08:00:00",
                "entryType": 1

        },
        {

                "name": "1c9",
                "location": "51",
                "ID": "79",
                "creationDate": "2019-06-26T18:27:10",
                "lastUpdatedDate": "2019-06-26T18:27:28",
                "startDate": "2019-06-26T08:00:00",
                "endDate": "2019-06-26T08:00:00",
                "entryType": 1
          }]
}

My DATA MODEL in proto3 file is:

message Entry{
  oneof Type {
   Fruit fruit = 1;
   Animal animals = 2;
   Bird birds = 3;

 }
}  

I tried using oneof type in the proto and used nested messaging in the backend go file to populate the model. Mysql is my database.

var allmt  pb.TypesResponse
for i := 0; i < len(dbEntries); i++ {
mt := &pb.TypesResponse{
            Entries: []*pb.Entry{{
                Type: &pb.Entry_Fruit{
                    dbEntries[i],
                },
            },
            },
        }
   allmt.Entries = append(allmt.Entries, mt.Entries[0])
}

Please help me in achieving the the flat json object.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.