github.com/clinia/x@v0.0.53/jsonx/raw.go (about) 1 package jsonx 2 3 import ( 4 "encoding/json" 5 ) 6 7 // Raw returns a json.RawMessage. 8 // This is useful for testing json payload. 9 // The function will panic if the input is not valid json. 10 // It normalize the json by unmarshaling and marshaling it again. 11 func RawMessage(bytesin string) json.RawMessage { 12 var v interface{} 13 err := json.Unmarshal([]byte(bytesin), &v) 14 if err != nil { 15 panic(err) 16 } 17 18 bytesout, err := json.Marshal(v) 19 if err != nil { 20 panic(err) 21 } 22 23 return bytesout 24 }