Golang encoding/json.RawMessage.UnmarshalJSON function example
package encoding/json
UnmarshalJSON sets *m to a copy of data.
Golang encoding/json.RawMessage.UnmarshalJSON function usage example
func MarshalSlice(in []interface{}) ([]byte, error) {
result := []*json.RawMessage{}
for _, value := range in {
bytes, err := Marshal(value)
if err != nil {
return nil, err
}
message := &json.RawMessage{}
message.UnmarshalJSON(bytes) // <--- here
result = append(result, message)
}
return json.Marshal(result)
}
References :
http://golang.org/pkg/encoding/json/#RawMessage.UnmarshalJSON
Advertisement
Something interesting
Tutorials
+13.8k Generate salted password with OpenSSL example
+4.7k Unix/Linux : How to pipe/save output of a command to file?
+8.1k Golang : HTTP Server Example
+5.6k Golang : Shortening import identifier
+15.6k Golang : Validate hostname
+9.7k Random number generation with crypto/rand in Go
+5.5k Golang : Stop goroutine without channel
+10.3k Golang : Convert file content to Hex
+9.4k Golang : Terminate-stay-resident or daemonize your program?
+15.9k Golang : Read a file line by line
+29.9k Golang : How to get HTTP request header information?
+9.6k Golang : How to extract video or image files from html source code