title: Redshift UDF - Returning JSON keys
body: <p>I'm trying to write a Redshift UDF with Python to return the keys of an JSON object:</p>
  
  <pre><code>create or replace function json_keys (j varchar(max))
      returns varchar(max)
      stable as $$
        import json
        arr = json.loads(j)
        for key in arr.keys():
        return str(key)
      $$ language plpythonu;
  </code></pre>
  
  <p>However when testing the function it only returns the last key in the object key i.e.</p>
  
  <pre><code>select json_keys('{"key1": "value1", "key2": "value2","key3": "value3"}') -- returns key3 only
  </code></pre>
  
  <p>What do I need to change to get it to return key1, key2 and key3?</p>