Function outputs are serialized as an escaped JSON string, as a result of using serde_json::to_string to serialize function output.
Consuming the data is unnecessarily complicated. One needs to clean the data, remove extra double-quotes ", and escape characters \ to transform it to a valid JSON byte array.
Example cleanup code:
// cleanNEAROracleRequestRaw transforms NEAROracleRequest.Result to a valid JSON.
// Currently the NEARQueryResult.Result for "get_requests" fn returns an escaped JSON string
// serialized as a byte array. We are unable to unmarshal this data directly and needs to be cleaned first.
// This is the result of Rust contracts serializing fn results using serde_json::to_string instead of serde_json::to_vec.
func cleanNEAROracleRequestRaw(data []byte) []byte {
str := string(data)
// remove escape dashes
strNoDash := strings.Replace(str, "\\", "", -1)
// remove first and last doublequote
strNoDashNoQuotes := strNoDash[1 : len(strNoDash)-1]
return []byte(strNoDashNoQuotes)
}
Consider using serde_json::to_vec which should hopefully avoid this problem.
Function outputs are serialized as an escaped JSON string, as a result of using
serde_json::to_string
to serialize function output.Consuming the data is unnecessarily complicated. One needs to clean the data, remove extra double-quotes
"
, and escape characters\
to transform it to a valid JSON byte array.Example cleanup code:
Consider using
serde_json::to_vec
which should hopefully avoid this problem.