9951 explained code solutions for 126 technologies

golangUnrmarshal example

package main
import "encoding/json"

type President struct {
  Name string
  Age int

func main() {
  s := `{"Name":"Joe","Age":99}`
  p := President{}
  json.Unmarshal([]byte(s), &p)
}ctrl + c
package main

default package declaration


lib to work with JSON

type President struct

defines struct with fields


struct name


sample json string to unmarshal into struct

p := President{}

this variable will store unmarshalled data


unmarshal given JSON string bytes and save result to what's given in second argument