Standard library / encoding/json
encoding/json.RawMessage
Byte slice representing pre-encoded JSON; useful for deferred decoding. json.Unmarshal copies incoming bytes into it. Expected stdout: '[1 2]\n'.
Formal Syntax & Structure
go syntaxgo
type RawMessage []byteWorking Example
Example Snippetgo
package main
import ( "encoding/json" "fmt")
func must(e error) { if e != nil { panic(e) }}
func main() { var x struct{ Payload json.RawMessage } must(json.Unmarshal([]byte(`{"Payload":[1,2]}`), &x)) var y []int must(json.Unmarshal(x.Payload, &y)) fmt.Println(y)}