title: Download JSON array to file
body: <p><strong>What is the recommended way for the following:</strong></p>
  
  <p><strong>An array of entities should be downloaded over a button. The button is called <code>Download transactions</code> and should do exactly that without forcing the user to "right click and 'save site as...'".</strong></p>
  
  <p>I have an entity <code>Transaction</code> and an array containing it.</p>
  
  <p>Entity:</p>
  
  <pre><code>export class Transaction {
    title: string;
    category: string;
    period: string;
    value: string;
  }
  </code></pre>
  
  <p>This was the last try I did to download this array as a file:</p>
  
  <pre><code>  exportJson(): void {
      console.log(this.transactions)
      const c = JSON.stringify(this.transactions);
      const file = new Blob([c], {type: 'text/json'});
      const fileURL = URL.createObjectURL(file);
      location.href = fileURL;
    }
  </code></pre>
  
  <p>This loads the tab containing the result in the current window, but as plain text and not as downloadable file.</p>
  
  <p>I know that there are a LOT of questions about this topic, none I found worked for me. Any help is appreciated! :)</p>