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
+17.8k Golang : Iterate linked list example
+5.8k Unix/Linux : Get reboot history or check when was the last reboot date
+6.1k nginx : force all pages to be SSL
+16.3k Golang : How to extract links from web page ?
+8.8k Golang : Accept any number of function arguments with three dots(...)
+10k Golang : Read file and convert content to string
+43.5k Golang : Get hardware information such as disk, memory and CPU usage
+25.7k Golang : How to write CSV data to file
+9.8k Golang : Resumable upload to Google Drive(RESTful) example
+7.7k Golang : Error reading timestamp with GORM or SQL driver
+41.2k Golang : How to count duplicate items in slice/array?
+48.1k Golang : How to convert JSON string to map and slice