Standard library / encoding/json
encoding/json.RawMessage.UnmarshalJSON()
Copy input bytes into the receiving RawMessage. When invoked by json.Unmarshal, input is valid JSON; the method itself does not validate it. Expected stdout: '123\n'.
Formal Syntax & Structure
go syntaxgo
func (m *RawMessage) UnmarshalJSON(data []byte) errorParameters & Attributes
| Name | Type | Description |
|---|---|---|
| data | []byte | Input bytes to decode. |
Return Value
error
Nil on success; otherwise an operation-specific error.
Working Example
Example Snippetgo
package main
import ( "encoding/json" "fmt")
func must(e error) { if e != nil { panic(e) }}
func main() { b := []byte(`123`) var m json.RawMessage must(m.UnmarshalJSON(b)) b[0] = '9' fmt.Println(string(m))}