I'm trying to learn a bit of Go, and while working through a few things, I spotted a little gotcha with marshalling JSON from `struct`s.
In tutorials and example code, I've seen a mix of `struct`s with uppercase field names:
```go
typeUserstruct{
Namestring
}
```
But also some with lowercase field names:
```go
typeUserstruct{
namestring
}
```
Thinking that this didn't matter, I started using lowercase names, as I'm more used to lowercase, as a Java developer, and to my surprise, found that serialising this to JSON didn't work.
The following code:
```go
packagemain
import(
"encoding/json"
"fmt"
)
typeUserstruct{
namestring
}
funcmain(){
r,err:=json.Marshal(User{name:"Bob"})
iferr!=nil{
panic(err)
}
fmt.Println(string(r))
}
```
Would return me the following output:
```json
{}
```
It turns out that this is an expected case, because [according to this answer on StackOverflow](https://stackoverflow.com/a/24837507/2257038):
> 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).
Therefore, the fix here was to make the following change, so the `Name` field would appear in the JSON as the `$.name` property: