Can't understand the logic of json.Marshal. Why is the output an empty object?

Please tell me. There is here such code:
type Test struct {
 text string `json:"test"`
}

var test test
 test.text = "test message"

 result, err := json.Marshal(test)

log.Println(test)
log.Println(result)
 log.Println(err)

Screen
1a63cbf7c2.jpg


why result = {}, not {"test message"}
Screen
1b07437fb4.jpg
April 3rd 20 at 18:41
3 answers
April 3rd 20 at 18:43
Solution
type Test struct {
 Text string `json:"test"`
}

Here's how it works. The answer is found here: Link
April 3rd 20 at 18:45
There is the fact that the field is `text` you have written with a small letter, which means it does not akrotiriou.
That is why such a result. And when you write it with big letters - it will work as you expect.
April 3rd 20 at 18:47
As stated in the Doc - https://blog.golang.org/json-and-go

Only data structures that can be represented as valid JSON will be encoded:

JSON objects only support strings as keys; to encode a Go map type it must be of the form map[string]T (where T is any Go type supported by the json package).
Channel, complex and function types cannot be encoded.
Cyclic data structures are not supported; they will cause the Marshal to go into an infinite loop.
Pointers will be encoded as the values they point to (or 'null' if the pointer is nil).
The json package only accesses the exported fields of struct types (those that begin with an uppercase letter). Therefore only the the exported fields of a struct will be present in the JSON output.

Find more questions by tags Go