go - Golang JSON RawMessage literal -


is possible create json.rawmessage literal in golang?

i want able this:

type errormessage struct {     timestamp string     message   json.rawmessage }  func gettestdata() errormessage {     return errormessage{         timestamp: "test-time",         message:   "{}"     } } 

or that. this succinct i've seen. have not been able find example of "struct" literal creating raw json messages.

the underlying data type json.rawmessage []byte

you can convert string, or use byte slice directly in literal

msg := errormessage{     timestamp: "test-time",     message:   []byte("{}"), } 

note marshal expected, need use *json.rawmessage, can't take address of in literal context.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -