How to Unmarshal (Decode) JSON in Go

Decode JSON data into Go variables using the json.Unmarshal function from the encoding/json package.

Use json.Unmarshal to decode JSON data into a Go variable by passing the JSON byte slice and a pointer to the target variable.

import "encoding/json"

var data map[string]interface{}
err := json.Unmarshal(jsonBytes, &data)
if err != nil {
    // handle error
}

For custom structs, define the struct with json tags and pass a pointer to an instance of that struct.