I have a json response that looks like this
{
"eventId":"fbf4a1a1-b4a3-4dfe-a01f-ec52c34e16e4",
"eventType":"event-type",
"eventNumber":0,
"data":"{\n \"a\": \"1\"\n}",
"metaData":"{\n \"yes\": \"no\"\n}",
"streamId":"test",
"isJson":true,
"isMetaData":true,
"isLinkMetaData":false,
"positionEventNumber":0,
"positionStreamId":"test",
"title":"0@test",
"id":"http://localhost:2113/streams/test/0",
"updated":"2017-12-14T05:09:58.816079Z"
}
the key value pairs of data, and metaData might sometimes be encoded json or it might not.
I want to decode those values into a byte array like this.
// Event represent an event to be stored.
type Event struct {
Data []byte `json:"data"`
Metadata []byte `json:"metaData"`
}
but when I try to unmarshal the json object I get the following error:
illegal base64 data at input byte 0
What could I be doing wrong here?
It works fine if I decode the data and metaData into a string, but I don't want to use a string.
[]byte encodes as a base64-encoded string, and the error also indicates that it's looking for base64 data. Can you just unmarshal into a string, and convert it as necessary?