$$ var o = {}; for (var i = 0; i < keys.length; i++) o[keys[i]] = vals[i]; return JSON.stringify(o); $$ LANGUAGE plv8 IMMUTABLE STRICT; ! SELECT to_jsontext(ARRAY['age', 'sex'], ARRAY['21', 'female']); to_jsontext ----------------------------- {"age":"21","sex":"female"} (1 row) Stored Procedures are hard to develop/test/maintain