Python

  1. import json
  2. import base64
  3. data = {'success': 0, 'message': 'ok', 'data': [i for i in range(10)]}
  4. enc_data = base64.b64encode(json.dumps(data).encode())
  5. # b'eyJzdWNjZXNzIjogMCwgIm1lc3NhZ2UiOiAib2siLCAiZGF0YSI6IFswLCAxLCAyLCAzLCA0LCA1LCA2LCA3LCA4LCA5XX0='
  6. base64.b64decode(enc_data)
  7. # b'{"success": 0, "message": "ok", "data": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}'

JavaScript

https://www.npmjs.com/package/crypto-js

https://www.npmjs.com/package/js-base64

  1. import * as CryptoJS from 'crypto-js';
  2. import * as Base64 from 'crypto-js/enc-base64';
  3. var words = CryptoJS.enc.Base64.parse('eyJzdWNjZXNzIjogMCwgIm1lc3NhZ2UiOiAib2siLCAiZGF0YSI6IFswLCAxLCAyLCAzLCA0LCA1LCA2LCA3LCA4LCA5XX0=')
  4. var data = words.toString(CryptoJS.enc.Utf8)
  5. // '{"success": 0, "message": "ok", "data": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}'
  6. JSON.parse(data)
  7. // {"success": 0, "message": "ok", "data": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}
  1. import { decode as b64decode } from 'js-base64';
  2. import { Base64 } from 'js-base64';
  3. b64decode('aGVsbG8gd29ybGQ=');
  4. Base64.decode('aGVsbG8gd29ybGQ=');