Declaring a name next to the field

(cinematik) #1

What does this notation mean when we declare some name next to the field?

type Poet struct {
    PS string `name:"testString"`

How to use it?

(Lutz Horn) #2

This is for example used to declare how the elements of a JSON object map to the struct members.

(Marc) #3


json:"key" you send key as key


json:"KeY" you send key as KeY


json:"KeY,omitempty" you send key as KeY, but is the value empty, it is not considered.