Skip to content

Mapstructure tags are ignored on slice struct items  #19

Description

@Thiht

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions