Skip to content

Instantly share code, notes, and snippets.

@voratham
Created August 17, 2019 15:35
Show Gist options
  • Select an option

  • Save voratham/fb935dc770f045eea56ba3155b030d6b to your computer and use it in GitHub Desktop.

Select an option

Save voratham/fb935dc770f045eea56ba3155b030d6b to your computer and use it in GitHub Desktop.
map_json.go
package main
import (
"encoding/json"
"fmt"
)
type userAccount struct {
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
}
func main() {
jsonString := `{ "firstName" : "Voratham" , "lastName" :"Siri"}`
fmt.Println(jsonString)
var user1 userAccount
jsonConveter(jsonString, &user1)
fmt.Println("user1 :: ", user1)
}
func jsonConveter(body string, data *userAccount) {
bs := []byte(body)
err := json.Unmarshal(bs, &data)
if err != nil {
fmt.Println("err :: ", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment