title: Check if key exists in a JSON with PL/pgSQL?
body: <p>I'm trying to check if a key exists in a JSON sent as parameter in a PL/pgSQL function.</p>
  
  <p>Here is the function.</p>
  
  <pre><code>CREATE FUNCTION sp_update_user(user_info json) RETURNS json
      LANGUAGE plpgsql
      AS $$
      BEGIN
      PERFORM user_info-&gt;&gt;'lastname';
      IF FOUND
      THEN
        UPDATE users SET lastname = user_info-&gt;&gt;'lastname' WHERE id = sp_update_user.user_id;
      END IF;
  
      PERFORM user_info-&gt;&gt;'firstname';
      IF FOUND
      THEN
        UPDATE users SET firstname = user_info-&gt;&gt;'firstname' WHERE id = sp_update_user.user_id;
      END IF;
  
      RETURN row_to_json(row) FROM (SELECT true AS success) row;
  END;$$;
  </code></pre>
  
  <p>I tried with the <code>PERFORM</code>-clause, but even if the json key does not exists, the statements in the <code>IF FOUND</code> clause are executed.</p>
  
  <p>I tried <code>PERFORM user_info-&gt;&gt;'firstname' INTO myvar;</code> in order to check the variable content but it triggers an error <code>ERROR:  query "SELECT user_info-&gt;&gt;'firstname' INTO myvar" is not a SELECT</code>.</p>
  
  <p>How can I check if a json key exists in a JSON with PL/pgSQL?</p>