On Sat, 26 Dec 2020, 10:25 am Hamsa Hesham, <hamsahesha...@gmail.com> wrote:

> package main
> import "encoding/json"
> import "log"
> import "fmt"
>
> type book struct {
>     ID        int
>     title     string
>     pubDate   string
>     author    string
>     genre     string
>     publisher string
>     language  string
> }
> func main(){
> b := book{
>     ID:    1,
>     title:   "Standard",
>     pubDate:      "Standard",
>     author: "Second-rate",
>     genre: "Standard",
>     publisher: "Standard",
>     language: "Standard",
> }
>
> var jsonData []byte
> jsonData, err := json.Marshal(b)
> if err != nil {
>     log.Println(err)
> }
> fmt.Println(string(jsonData))
>
> }
>
> The output is {"ID":1}  .. why?!!
>

Your struct fields will need to start with a capital letter to be
exportable into JSON. Since ID is the only field here, you only see that in
your output.


-- 
> 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/44b561be-30eb-48cb-ae0c-5d56f09e1c2cn%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/44b561be-30eb-48cb-ae0c-5d56f09e1c2cn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CANODV3krc-uo7FO%2BpFnmqYaBdiD4C1wPeFxo6NW_mt96Vt8gqQ%40mail.gmail.com.

Reply via email to