When downloading content from the server into a file and dealing with multiple lines of JSON, an unexpected token error occurs due to new line characters. How can this issue be resolved?
Data from the server
{"level":"info","message":"Test Log messages"}
{"level":"info","message":"Test Log messages"}
{"level":"info","message":"Test Log messages"}
ctrl.js
$scope.downloadFile = function(message){
DitFactory.getFile(message).then(function(response,$window){
var data = JSON.stringify(response.data);
var blob = new Blob([data], { type: 'text/plain;charset=utf-8' });
FileSaver.saveAs(blob, 'text.txt');
console.log(response);
});
};
Error
angular.js:13708 SyntaxError: Unexpected token { in JSON at position 49
at Object.parse (native)
at fromJson