xxxxxxxxxx
JSON to Base64:
function jsonToBase64(object) {
const json = JSON.stringify(object);
return Buffer.from(json).toString("base64");
}
Base64 to JSON:
function base64ToJson(base64String) {
const json = Buffer.from(base64String, "base64").toString();
return JSON.parse(json);
}
xxxxxxxxxx
const json = { "a": 1, "b": 2 }
const string = JSON.stringify(json) // convert Object to a String
const encodedString = btoa(string) // Base64 encode the String