Store and Load JSON in Script Properties

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!

NitroGAS Chrome Extension

Want this snippet handy inside the Apps Script editor? NitroGAS gives you free themes and snippets — plus optional Co-Pilot when you want a boost (1-week, 1-month, or yearly passes — no subscription). Happy Coding!

Get the Extension