10 examples of 'json to base64' in JavaScript

Every line of 'json to base64' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
139function toBase64(text){
140 return Base64.encode(text);
141}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

88function toBase64(input) {
89 return $.base64.encode(input);
90}
32function base64Decode(base64) {
33 base64 = base64.replace(/\*/g,'+').replace(/-/g,'/').replace(/\_/g,'=');
34 let result = new Buffer(base64, 'base64').toString();
35 return result;
36}
14export default function toBase64(val: string | Buffer) {
15 if (val instanceof Buffer) return val.toString('base64');
16 return Buffer.from(val).toString('base64');
17}
33function decodeDataToBase64(encodedData) {
34 return window.atob(encodedData);
35}
28function base64(s) {
29 return window.btoa(s).split('=')[0]
30}
65function b64_encode(data) {
66 var o1, o2, o3, h1, h2, h3, h4, bits, r, i = 0, enc = "";
67 if (!data) { return data; }
68 do {
69 o1 = data[i++];
70 o2 = data[i++];
71 o3 = data[i++];
72 bits = o1 << 16 | o2 << 8 | o3;
73 h1 = bits >> 18 & 0x3f;
74 h2 = bits >> 12 & 0x3f;
75 h3 = bits >> 6 & 0x3f;
76 h4 = bits & 0x3f;
77 enc += b64_table.charAt(h1) + b64_table.charAt(h2) + b64_table.charAt(h3) + b64_table.charAt(h4);
78 } while (i < data.length);
79 r = data.length % 3;
80 return (r ? enc.slice(0, r - 3) : enc) + "===".slice(r || 3);
81}
2function arrayBufferToBase64(buffer) {
3 return buffer.toString('binary');
4}
93function toBase64_1(typedArray) {
94 return ( new Buffer(typedArray.buffer)).toString("base64");
95}
122function base64Decode(str) {
123 var buffer = new Buffer(str, 'base64');
124
125 try {
126 return JSON.parse(buffer.toString('ascii'));
127 } catch (err) {
128 return null;
129 }
130}

Related snippets