Created
May 15, 2018 13:59
-
-
Save soobrosa/52b7e73ef4ca66a61ec52933fe90d325 to your computer and use it in GitHub Desktop.
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 CLEAN_DEEP_JSON (j VARCHAR(65535), f VARCHAR(65535)) | |
RETURNS VARCHAR(MAX) | |
STABLE AS $$ | |
import json | |
if not j: | |
return None | |
try: | |
arr = json.loads(j) | |
except valueerror: | |
return None | |
fs = f.split('$') | |
for l in fs: | |
if l in arr: | |
arr = arr[l] | |
else: | |
return None | |
return str(arr) | |
$$ LANGUAGE PLPYTHONU; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment