Declare json object in golang

Code examples

0
0

create json in go

package main
 
import (
    "fmt"
    "encoding/json"
)
 
type Book struct {
    Name string
    Author string
}
 
func main() {
    book := Book{"C++ programming language", "Bjarne Stroutsrup"}
    res, err := json.Marshal(book)
     
    if err != nil {
        fmt.Println(err)
    }
     
    fmt.Println(string(res))      // {"Name":"C++ programming language","Author":"Bjarne Stroutsrup"}
}

// See more in the source

Similar pages

Similar pages with examples

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................