const json = { "a": 1, "b": 2 } const string = JSON.stringify(json) // convert Object to a String const encodedString = btoa(string) // Base64 encode the String