-4

i would know if json.Marshal Put Uppercase a the first letter of each name fields ? I need to encode some data with just a lowercase at each field name first letter.

just:

{
  "name":"thomas"
}

instead of:

{
  "Name":"thomas"
}

Thanks !

RieuxThomas
  • 49
  • 2
  • 9

1 Answers1

1

You have to add an annotation to the Name field.

Supposing your struct is:

type User struct {
    Name string
 }

You have to change it to:

type User struct {
    Name string `json:"name"`
 }

The json marshaller will replace Name with name

nessuno
  • 26,493
  • 5
  • 83
  • 74