This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION escape_json (text) RETURNS text AS $$ | |
SELECT replace($1, '''', '\'''); $$ LANGUAGE SQL IMMUTABLE; | |
CREATE OR REPLACE FUNCTION to_json(text) RETURNS text AS $$ | |
SELECT escape_json($1) $$ LANGUAGE SQL IMMUTABLE; | |
CREATE OR REPLACE FUNCTION to_json(KEY text, value text) RETURNS text AS $$ | |
SELECT '''' || to_json($1) || ''': ''' || to_json($2) || ''''; $$ LANGUAGE SQL IMMUTABLE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION json_access(obj json, path text) RETURNS json AS $$ | |
var obj = JSON.parse(obj); | |
var paths = path.split("."); | |
var p; | |
var ret; | |
while (p = paths.shift()) { | |
if (typeof obj[p] == 'undefined'){ | |
obj = null; | |
break | |
} |