gokv
gokv copied to clipboard
Add option to keep JSON readable for some implementations
Currently, when JSON is used as MarshalFormat
, it will always be converted to []byte
. This makes the result unreadable as a human, unless interpreted as / converted back to string
. So for example when using DynamoDB, and a struct is marshalled into a JSON {"Foo":"bar"}
, saved to DynamoDB with gokv
, and then you look at the value via the AWS console, it's just eyJGb28iOiJiYXIifQ==
, the Base64 encoding of the JSON string.
That's because in the dynamodb
implementation we use a awsdynamodb.AttributeValue
for the value where we assign the value to a field B
, which is for []byte
, and has the Base64 encoding described in the comment:
// An attribute of type Binary. For example:
//
// "B": "dGhpcyB0ZXh0IGlzIGJhc2U2NC1lbmNvZGVk"
//
// B is automatically base64 encoded/decoded by the SDK.
B []byte `type:"blob"`
In this case, we could look at the option provided by the package user and instead of B
, use S
and assign the plain JSON string to it.
This should also be done in a similar way for other implementations. It only makes sense for some of them though!