title: How can i combine rows range into json format?
body: <p>I have a google sheet like this</p>
  
  <p><img src="https://i.imgur.com/BKKB1LL.jpg" alt="https://i.imgur.com/BKKB1LL.jpg"></p>
  
  <p>The number of columns and rows may be different (not static). I want my google script to look for last row and column, then run a for loop and combine data of each row into this json format like this.</p>
  
  <pre><code>[["1","Lee","Blue","Active"],["2","Mike","Green","Disabled"],["3","Chan","Yellow","Active"]]
  </code></pre>
  
  <p>I learned about the JSON.stringify() function that helps and I am able to combine data or each row into json format BUT i want each row data separated by a comma (,), not sure how to add that in the logic since I DO NOT want comma to be added after LAST row.</p>
  
  <p>I have tried creating this code and need help with the logic to dynamically run the loop based on number of columns and rows instead of hard-coding any range and add comma.</p>
  
  <pre><code>var mysheet = SpreadsheetApp.getActive().getSheetByName('mysheet');
  
  function combine_val() {
  
  GetRowsCount();
  var startRow = 2; // First row of data to process
  var numRows = LastAudienceRow; // Number of rows to process
  
  for (var i = 0; i &lt; numRows; ++i) {
  var dataRange = mysheet.getRange(startRow, 1, 1, 4);
  var data = dataRange.getValues();
  startRow = startRow+1;
  var data2= JSON.stringify(data);
  }
  
  SpreadsheetApp.getUi().alert(data2); 
  
  }
  
  
  
  function GetRowsCount() {
  LastAudienceRow = mysheet.getLastRow() - 1;
  return LastAudienceRow;
  
  }
  </code></pre>