5

From Slack:

i saved data to an account as {foo: 'bar'}, but it came back as: { foo: 'YmFy' }. What encoding is being used, and/or how do you get the plain text/utf8 value?

5

Account data is encoded with base64.

Note that the key must be a string but data can be any kind of binary data (in addition to a string), so that's why many APIs return it base-64 encoded.

Some examples of decoding this value in various languages:

Javascript

var decoded = atob('YmFy'); // 'bar'

Go

decoded, err := base64.StdEncoding.DecodeString("YmFy")
if err != nil {
    fmt.Println("decode error:", err)
    return
}
fmt.Println(string(decoded))

PHP

$decoded = base64_decode('YmFy');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.