Reputation: 528
My code generates "data" containing a json. I need to separate the HEX-value from the Buffer, and decode it from HEX->BASE64->UTF8 into a string.
Code:
console.log(data);
Output:
> { ContentType: 'application/json', InvokedProductionVariant:
> 'AllTraffic', Body: <Buffer 7b 22 73 63 6f 72 65 73 22 3a 5b 7b 22
> 73 63 6f 72 65 22 3a 32 2e 35 31 35 30 34 32 33 37 32 39 7d 5d 7d> }
Code below works for base64 to utf8. But the steps inbetween I cannot figure out or find answer to.
Buffer.from("...", 'base64').toString('utf8'));
Upvotes: 0
Views: 101
Reputation: 24221
Your data object's Body, is already Buffer, so all you need to do is convert that buffer.
console.log(data.Body.toString('utf8'));
Looks like this is JSON, so even better would be ->
const ret = JSON.parse(data.Body.toString('utf8'));
console.log(ret.scores[0].score);
Upvotes: 1