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
+9.1k Golang : Handle sub domain with Gin
+80.7k Golang : How to return HTTP status code?
+20.2k Golang : Reset or rewind io.Reader or io.Writer
+11.7k Golang : Calculations using complex numbers example
+7.1k Golang : Transform lisp or spinal case to Pascal case example
+6.4k PHP : Proper way to get UTF-8 character or string length
+12.3k Golang : How to check if a string starts or ends with certain characters or words?
+5.3k Javascript : Change page title to get viewer attention
+40.5k Golang : Convert to io.ReadSeeker type
+13k Swift : Convert (cast) Int to String ?
+19.1k Golang : Clearing slice
+22.7k Golang : Strings to lowercase and uppercase example