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
+19.3k Golang : Calculate entire request body length during run time
+12.3k Golang : Get month name from date example
+8.3k Golang: Prevent over writing file with md5 hash
+22.6k Generate checksum for a file in Go
+7k Golang : Levenshtein distance example
+7.4k Golang : Accessing dataframe-go element by row, column and name example
+19.9k Golang : Count JSON objects and convert to slice/array
+17.2k Golang : When to use init() function?
+5.8k Golang : Launching your executable inside a console under Linux
+9.1k Golang : Gonum standard normal random numbers example
+10.7k Golang : Interfacing with PayPal's IPN(Instant Payment Notification) example
+30k Golang : Get time.Duration in year, month, week or day