Published using Google Docs
ScriptDB JSON to Spreadsheets
Updated automatically every 5 minutes

HNBG6TEUI0O8

 -..7´¿¿8777563+WZQiooooooooooooooooooooooz<-*function dumpScriptDbIntoSheet() {

  var db = <YOUR LIBRARY’S NAME>.getDb();

// Remember to adjust the Query to your needs.

  var result = db.query({}).startAt(0).limit(1000); // Here you change the range

  var data = [];

  var keys = {};

// load in data and find out the object keys

  while (result.hasNext()) {

    var nextResult = result.next();

// Change to NextResult.<someJSONclass> to get specific nested JSON objects

    var item = nextResult; 

    var itemKeys = Object.keys(item);

    for (var i = 0; i < itemKeys.length; i++) {

      if (typeof(item[itemKeys[i]]) != 'function') {

        keys[itemKeys[i]] = true;

      }

    };

    data.push(item);

  }

  var headings = .keys(keys);

  var values = [headings];

  // produce the values array containing the bits from the result objects

  for (var rownum = 0 ; rownum < data.length; rownum++) {

    var thisRow = [];

    var item = data[rownum];

    for (var i = 0; i < headings.length; i++) {

      var field = headings[i];

      var thisValue = item[field];

      if (thisValue == undefined

s.push(thisRow);3.00.

  }

  var spreadsheet = SpreadsheetApp.openById("<YOU SPREADSHEEET’S ID>");

  var sheet = spreadsheet.insertSheet(Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd"));

  var range = sheet.getRange(1, 1,

      values.length, headings.length);

  range.setValues(values);

}