Format JSON file automatically during download

0

I download a file in JSON format and the contents of the file all appear in a giant line, without indenting.

Example:

{"Oi":"xxxxx","tUDO":"YYY","BEM":"ZZZZZ"}

Just imagine the example above with more than 3000 characters in text.

I'd like to know if there is a way I can download the file right now, from 1) indent. For example:

{
    "Oi":"xxxxx",
    "tUDO":"YYY",
    "BEM":"ZZZZZ"
}

2) Convert to .txt

    
asked by anonymous 05.10.2017 / 14:14

2 answers

0

Simple!

<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>
 <script>
  function text(nome, valor){
    var a = document.createElement('a');
    var blob = new Blob([ valor ], {'type':'application/octet-stream'});
    a.href = window.URL.createObjectURL(blob);
    a.download = nome;
    a.click();
 }

var json = {"Oi":"xxxxx","tUDO":"YYY","BEM":"ZZZZZ"};
var nome = "text.txt";

text( nome , JSON.stringify( json ) );

</script>

    
06.10.2017 / 16:13
-1

Opa Rodrigo, try to use this site:

link

    
05.10.2017 / 14:44