a função json.Unmarshal() pega alguns dados JSON codificados e um ponteiro para um valor onde o JSON codificado deve ser escrito e retorna um erro se algo der errado.
func Unmarshal(data []byte, v interface{}) error
package main
import (
"fmt"
"encoding/json"
)
type Pessoa struct {
Nome string
Idade int
}
type Livro struct {
Autor Pessoa
func main() {
// Marshal
domQuixote := Livro{
"Dom Quixote",
Pessoa{
"Miguel de Cervantes",
44,
},
res, err := json.Marshal(domQuixote)
if err != nil {
fmt.Println(err)
fmt.Println("Marshal", string(res))
// Unmarshal
outroLivro := Livro{}
err = json.Unmarshal(res, &outroLivro)
fmt.Println("Unmarshal", outroLivro)