0
{
"report": "IkFncmVlbWVudCBObyIsIkxlYXNlIEV4cCBEYXRlIiwiTmFtZSBPZiBMZXNlZSIsIkVuZ2luZSBObyIsIkNoYXNzaXMgTm8iLCJSZWcuIE51bWJlciIsIkFtdC4gRmluYW5jZWQiLCJNb250aGx5IFJlbnQiLCJQZXJpb2QiLCJSZW50IFBhaWQiLCJQYWlkIFZhbHVlIiwiRlJSIiwibnVsbCUgRlJSIiwiQnJhbmNoIiwiUmVudGFscyBSY3ZkIiwiQXJyZWFycyA+IDIgbW9udGhzIiwiRGlzdHJpY3QiLAoibnVsbCIsIm51bGwiLCJudWxsIiwibnVsbCIsIm51bGwiLCJudWxsIiwiMC4wIiwiMC4wIiwibnVsbCIsIm51bGwiLCIwLjAiLCIwLjAiLCIwLjAiLCJudWxsIiwiMC4wIiwiMC4wIiwibnVsbCIs",
"fileName": "TrancheReport.csv"
}

I got a byte stream like the above and it needs to be converted in to string with javascript. Could anyone help with the above scenario ?

zt1983811
  • 1,011
  • 3
  • 14
  • 34
  • See https://stackoverflow.com/q/16245767/215552 to convert the base64 string to a byte array, then https://stackoverflow.com/q/3195865/215552 to convert the byte array to a string (specifically [this answer](https://stackoverflow.com/a/37542820/215552) for its brevity). – Heretic Monkey Jun 17 '17 at 03:43

1 Answers1

0

You can use atob() that decodes a string of data which has been encoded using base-64 encoding.

var json = {
  "report": "IkFncmVlbWVudCBObyIsIkxlYXNlIEV4cCBEYXRlIiwiTmFtZSBPZiBMZXNlZSIsIkVuZ2luZSBObyIsIkNoYXNzaXMgTm8iLCJSZWcuIE51bWJlciIsIkFtdC4gRmluYW5jZWQiLCJNb250aGx5IFJlbnQiLCJQZXJpb2QiLCJSZW50IFBhaWQiLCJQYWlkIFZhbHVlIiwiRlJSIiwibnVsbCUgRlJSIiwiQnJhbmNoIiwiUmVudGFscyBSY3ZkIiwiQXJyZWFycyA+IDIgbW9udGhzIiwiRGlzdHJpY3QiLAoibnVsbCIsIm51bGwiLCJudWxsIiwibnVsbCIsIm51bGwiLCJudWxsIiwiMC4wIiwiMC4wIiwibnVsbCIsIm51bGwiLCIwLjAiLCIwLjAiLCIwLjAiLCJudWxsIiwiMC4wIiwiMC4wIiwibnVsbCIs",
  "fileName": "TrancheReport.csv"
};

var str = atob(json.report);

console.log(str);
luisenrike
  • 2,742
  • 17
  • 23