title: Export JSON to CSV or Excel with UTF-8 (e.g. Greek) encoding using JavaScript
body: <p>I am trying to export and download a <em>JSON</em> object to <em>CSV</em> file and I have problem with Greek characters. My code works; it is not perfect, but it works. </p>
  
  <p>The problem is that Greek characters looks like junk. </p>
  
  <p>Here is my existing code:</p>
  
  <pre><code>function downloadJsonToCsv(jsonObject) {
      var array = typeof jsonObject != "object" ? JSON.parse(jsonObject) : jsonObject;
  
      if (array == null) {
          return; // No data found on the jsonObject
      }
  
      var str = "";
  
      for (var i = 0; i &lt; array.length; i++) {
          var line = "";
  
          for (var index in array[i]) {
              line += array[i][index] + ";"; // Set delimiter
          }
  
          // Here is an example where you would wrap the values in double quotes
          // for (var index in array[i]) {
          //    line += '"' + array[i][index] + '",';
          // }
  
          line.slice(0,line.Length-1); 
  
          str += line + "\r\n";
      }
  
      window.open("data:text/csv;charset=utf-8," + encodeURI(str));
  }
  </code></pre>
  
  <p>I have two questions.</p>
  
  <ol>
  <li>How can export this <em>CSV</em> file with correct Greek chars?</li>
  <li>How can I export this data in <em>Excel</em> format and not in <em>CSV</em> format?</li>
  </ol>