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
+12.7k Golang : Pass database connection to function called from another package and HTTP Handler
+32.1k Golang : Validate email address with regular expression
+19.9k Golang : Accept input from user with fmt.Scanf skipped white spaces and how to fix it
+17.9k Golang : How to make a file read only and set it to writable again?
+9k Golang : Capture text return from exec function example
+13.3k Golang : Linear algebra and matrix calculation example
+14.8k Golang : Adding XML attributes to xml data or use attribute to differentiate a common tag name
+19.3k Golang : Get RGBA values of each image pixel
+3.7k Golang : Switch Redis database redis.NewClient
+8.9k Golang : Sort lines of text example
+7.5k Golang : Rot13 and Rot5 algorithms example
+16.6k Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file