Skip to content

Instantly share code, notes, and snippets.

@soobrosa
Created May 15, 2018 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soobrosa/52b7e73ef4ca66a61ec52933fe90d325 to your computer and use it in GitHub Desktop.
Save soobrosa/52b7e73ef4ca66a61ec52933fe90d325 to your computer and use it in GitHub Desktop.
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