This is not a real "why", but this how json.Marshal works according to the 
documentation. From https://pkg.go.dev/encoding/json#Marshal:

"Struct values encode as JSON objects. Each exported struct field becomes a 
member of the object, using the field name as the object key, unless the 
field is omitted for one of the reasons given below."

(Note that struct fields that start with an uppercase letter are 
"exported", and fields starting with a lowercase letter is "not exported" 
or "unexported", as per https://go.dev/ref/spec#Exported_identifiers) 

I doubt it could change at this point, it would potentially cause libraries 
to start leaking information from structs to the json representation that 
people expected to stay private.

If you have a specific problem you are trying to solve, someone may be able 
to help if you explain what you are actually trying to achieve.

On Thursday, December 23, 2021 at 11:23:42 AM UTC-7 A JI wrote:

> Why, when the object of struct is lowercase. I can't fill it and convert 
> to JSON ?
>
> https://go.dev/play/p/WZCvC7M5YAp
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/3d1dd2ea-e199-40f5-a397-f7f808b2f7d2n%40googlegroups.com.

Reply via email to