![GASのスクリプトプロパティをjsonで取得したい](https://devio2023-media.developers.io/wp-content/uploads/2019/08/google-apps-script-logo-1200x630.png)
GASのスクリプトプロパティをjsonで取得したい
ファイルに保存しときたいけど、毎回忘れてしまうやつ。
PropertiesService
クラスのgetScriptProperties()
を使用することでスクリプトプロパティの内容を取得できる。
jsonにするのはJSON.stringify()
を使ってjson文字列にすることができます。
const properties = PropertiesService.getScriptProperties().getProperties(); console.log(JSON.stringify(properties))
ちなみに、jsonファイルをGoogle Driveに保存するには、
DriveApp
クラスを使うことで可能です。
const properties = PropertiesService.getScriptProperties().getProperties(); const jsonStr = JSON.stringify(properties); // 保存 const folder = DriveApp.getFolderById('<<フォルダID>>'); //フォルダIDを指定 folder.createFile('property.json', jsonStr, MimeType.PLAIN_TEXT);
createFile()
で新規にファイルを保存してみました。