3000 explained code solutions for 75 technologies

golangHow to parse JSON and convert to struct

package main
import (

type data struct {
  A int
  B int

func main() {
  json_str := `{"A":25,"B":13}`
  var res data
  json.Unmarshal([]byte(json_str), &res)
}ctrl + c
package main

default package declaration

func main() {

declare main function that will be launched automatically


sample JSON string to parse


variable of data struct type


parses given JSON string (bytes) and saves result to res