To have a JSon format with lower-case field names one has to (1) use field
names beginning with upper case - to enable export and (2) use json
annotations to force a field name.
Just have a look at the following example:
https://gobyexample.com/json  <https://gobyexample.com/json>


Am Sa., 26. Dez. 2020 um 01:30 Uhr schrieb Amit Saha <amitsaha...@gmail.com
>:

>
>
> 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
> <https://groups.google.com/d/msgid/golang-nuts/CANODV3krc-uo7FO%2BpFnmqYaBdiD4C1wPeFxo6NW_mt96Vt8gqQ%40mail.gmail.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/CA%2B8p0G0tNU5uHgXbaxT%3DYSXkVvsFj_KY0C5dU85gXfaRqf52jA%40mail.gmail.com.

Reply via email to