I'm trying to convert a struct to a map, and can't figure out how to make it work.
Basically I have these structs:
type SQLStepResult struct {
Queries []QueryResult `mapstructure:"queries"`
}
type QueryResult struct {
Rows []map[string]any `mapstructure:"rows"`
}
and I want to convert SQLStepResult to:
{
"queries": [
{
"rows": [
// ...
]
}
]
}
But I always end up with Rows instead of rows.
I tried using the undocumented mapstructure.RecursiveStructToMapHookFunc but it doesn't appear to do anything
Is there a solution?
Go playground for reference: https://go.dev/play/p/ZlTOw1mqnH5
I'm trying to convert a struct to a map, and can't figure out how to make it work.
Basically I have these structs:
and I want to convert
SQLStepResultto:{ "queries": [ { "rows": [ // ... ] } ] }But I always end up with
Rowsinstead ofrows.I tried using the undocumented
mapstructure.RecursiveStructToMapHookFuncbut it doesn't appear to do anythingIs there a solution?
Go playground for reference: https://go.dev/play/p/ZlTOw1mqnH5