So I have this struct:
type AllShipments struct {
Shipments []struct {
ShipmentID int `json:"shipmentId"`
ShipmentDate time.Time `json:"shipmentDate"`
ShipmentItems []struct {
OrderItemID string `json:"orderItemId"`
OrderID string `json:"orderId"`
} `json:"shipmentItems"`
Transport struct {
TransportID int `json:"transportId"`
} `json:"transport"`
} `json:"shipments"`
}
I want to get a list containing only the shipmentID values, because I need it to make API calls to get specific details of a single shipment. Then later I can loop over it in my API calls.
In Python I did this:
# Create shipments dataframe
df_shipments = json_normalize(full_df['shipments'], 'shipmentItems', columns)
# Turn into list so we can loop over the shipmentId property in our API call to get more detailed information
ship_list = df_shipments['shipmentId'].tolist()
Very powerfull, with two lines of code. But a lot of magic going on. I want to do the same with Golang. From the docs and some searching I came up with this idea:
var shipmentList []string
for _, v := range t.Shipments {
shipmentList = append(shipmentList, string(v.ShipmentID))
}
Then the shipmentList
should return me an array containing all the shipmentID's. But I get this output: [� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �]
Can someone maybe clarify what is going on and why I get this result? And how to get the expected result I want?