Capitals in struct fields

This is because only fields starting with a capital letter are exported, or in other words visible outside the curent package (and in the json package in this case).

Here is the part of the specifications refering to this: http://golang.org/ref/spec#Exported_identifiers

Still, you can unmarshall json fields that do no start with a capital letters using what is called “tags”. With the json package, this is the syntax to use:

type Sample struct {
    Name string `json:"name"`
    Age  int    `json:"age"`
}

Refer to the documentation for more information about this.

Leave a Comment