Script Properties are great for small config blobs — tokens, last-run watermarks, feature flags. These helpers wrap JSON.stringify / JSON.parse so you don't sprinkle try/catch everywhere.
What you'll need
- Permission to use Script Properties (default for the project)
- Keys that stay small — Properties have size limits (~9KB per property)
How to use this snippet
function getJson(key, fallback) {
var raw = PropertiesService.getScriptProperties().getProperty(key);
if (raw == null || raw === '') return fallback;
return JSON.parse(raw);
}
function setJson(key, value) {
PropertiesService.getScriptProperties().setProperty(key, JSON.stringify(value));
}
function saveCursor(isoDate) {
setJson('syncCursor', { lastRun: isoDate });
}
function loadCursor() {
return getJson('syncCursor', { lastRun: null });
}
Tips:
- Don't store secrets in source control — set them once via the editor or a setup function, then read with
getJson. - For per-user settings, swap to
PropertiesService.getUserProperties().
Happy Coding!
