Encoding JSON to Base64


Does anyone knows how I could encode JSON object to base64?

I have seen a few posts but only works for converting strings.

From @emre
function b64(input)
var convert = host.type(“System.Convert”);
var encoding = host.type(“System.Text.Encoding”);
var inputBytes = encoding.UTF8.GetBytes(input);
// return convert.ToBase64String(inputBytes);

return encoding.ToBase64String()

Here is my JSON data:


For all intents and purposes, JSON is a string until it’s deserialised/converted into an object. Passing your JSON data direct to the function should work.

On another note, why convert to Base64?

I passed the JSON Data as string and that worked.

I am required to include a QR Code in all receipts. QR must include: (URL) + (Base64 enconded JSON).

Thank you Memo!

1 Like
let objJsonStr = JSON.stringify(obj);
let objJsonB64 = Buffer.from(objJsonStr).toString("base64");

May be it will help you, obj = your json