I used below code for the create and download the file. But below the code only work when click the link. so how to download the file by default load. without click.
<script>
array=[{a:'1',b:'2'},{x:'3',y:'4'}];
function dl(array,filename){
var b=document.createElement('a');
b.download=filename;
b.textContent=filename;
b.href='data:application/json;base64,'+window.btoa(unescape(encodeURIComponent(JSON.stringify(array))))
return b
}
document.body.appendChild(dl(array,'my.json'));
</script>