Let's say I have a json that looks like this:
some_json = {'key_a': {'nested_key': 'a'},
'key_b': {'nested_key': 'b'}}
Note that key_a
and key_b
are optional keys mapped to dictionaries and may or may not exist.
I have a function that checks if an outer key exists in some_json
and returns a boolean.
CREATE FUNCTION key_exists(some_json json, outer_key text)
RETURNS boolean AS $$
BEGIN
RETURN (some_json->outer_key IS NULL);
END;
$$ LANGUAGE plpgsql;
I get the following error:
ProgrammingError: operator does not exist: json -> boolean
Why is outer_key
equating to a boolean? What's the proper syntax to perform this check?