10
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Gasでgoogle Spreadsheetをjsonで返す方法

Last updated at Posted at 2019-06-14

とりあえず適当に入力する
スクリーンショット 2019-06-14 9.56.16.png

お次はツール > スクリプトエディタでスクリプト書いていきます

スクリーンショット 2019-06-14 9.57.59.png

ソースは下記から引用

https://www.koreyome.com/web/make-spreadsheet-to-json-at-google-apps-script/

function getData(id, sheetName) {
  var sheet = SpreadsheetApp.openById(id).getSheetByName(sheetName);
  var rows = sheet.getDataRange().getValues();
  var keys = rows.splice(0, 1)[0];
  return rows.map(function(row) {
    var obj = {}
    row.map(function(item, index) {
      obj[keys[index]] = item;
    });
    return obj;
  });
}
 
function doGet(request) {
  var func = 'jsondata';
  var data = getData('xxx_スプレッドシートのURL_xxx', 'Sheet1');
  return ContentService.createTextOutput(func + '(' + JSON.stringify(data, null, 2) + ')')
  .setMimeType(ContentService.MimeType.JAVASCRIPT);
}

あとは公開するだけ
スクリーンショット 2019-06-14 10.01.45.png

赤枠で囲っているURLをgetするだけ
スクリーンショット_2019-06-14_10_02_18.png

こんな感じでjson吐いてくるyo
スクリーンショット 2019-06-14 10.06.22.png

10
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?