Skip to content

tm.decode ​

Safe read of a JSON column: tm.decode(value, fallback). Replaces the per-resource local function decode copies. Shared.

lua
local data = tm.decode(row.data, {})
data.visits = (data.visits or 0) + 1   -- safe: every call returns a fresh table
  • A table passes through untouched (a driver can already hand back decoded JSON).
  • A non-empty JSON string is decoded with the native json.decode.
  • Anything else returns fallback: nil, an empty string, 'null', malformed JSON, or JSON that is not an object or array ('5', '"x"').

There is no decode cache, so a mutated row never leaks into the next read.