title: Apps Script - Export JSON properly into Google Sheet
body: <p>I'm quite beginner with Apps Script / Javascript. I have some JSON data that I'm exporting using an API.</p>
  <p>Below is what I get when I do: <code>console.log(jsonData);</code></p>
  <p><a href="https://i.stack.imgur.com/1g0z2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1g0z2.png" alt="JSON data sample" /></a></p>
  <p>I'm trying to:</p>
  <ul>
  <li>Transform this JSON data into CSV.</li>
  <li>Put the data in the first sheet of my active spreadsheet</li>
  </ul>
  <p>Basically it should look like this:</p>
  <p><a href="https://i.stack.imgur.com/q7AEw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q7AEw.png" alt="Google Sheet output" /></a></p>
  <p>However I'm stuck at this step and I cannot get the next piece of code right ... (how to transform into CSV and putting the data in a Google sheet).</p>
  <p>Below is the beginning of my script:</p>
  <pre><code>function myFunction() {
    
    var apiKey = &quot;MyApiKEY&quot;;
    var now = new Date();
    var startDate = new Date(now.setDate(now.getDate()-2))
    var endDate = startDate
  
    var startDateFormatted = Utilities.formatDate(new Date(startDate), &quot;GMT+7&quot;, &quot;yyyy-MM-dd&quot;);
    var endDateFormatted = Utilities.formatDate(new Date(endDate), &quot;GMT+7&quot;, &quot;yyyy-MM-dd&quot;);
  
    var url = 'https://public-api.vendor.com/v1/clicks?start_date='+ startDateFormatted + '&amp;end_date=' + endDateFormatted;
    var options1 = {
      &quot;method&quot;: &quot;get&quot;,
      &quot;headers&quot;: {
        &quot;accept&quot;: &quot;application/json&quot;,
        &quot;Authorization&quot;: apiKey
      }
     }
    var response = UrlFetchApp.fetch(url, options1);
    var jsonData = JSON.parse(response.getContentText());
  
    // console.log(jsonData);
  
  }
  </code></pre>
  <p>I would appreciate any help in getting those data into a Google Sheet.
  Also feel free to modify anything in the beginning of my script if you think something is wrong or unnecessary.</p>