Is there a way to filter out null keys for my json? This is using Apache AGE extension:
SELECT json_object_agg(k, v)
FROM cypher('hermech', $$
MATCH (a:contact_name)
WHERE id(a) = 10133099161583644
OPTIONAL MATCH (a)-[:DIRECT_EMAIL_ADDRESS]->(b:direct_email_address)
OPTIONAL MATCH (a)<-[:CONTACT_NAME]-(c:account_name)
OPTIONAL MATCH (c)-[:MAIN_PHONE_NUMBER]->(d:main_phone_number)
OPTIONAL MATCH (c)-[:MAIN_STREET_ADDRESS]->(e:main_street_address)
OPTIONAL MATCH (c)-[:MAIN_DOMAIN]->(f:main_domain)
WITH [a,b,c,d,e,f] AS nodes
UNWIND nodes AS n
RETURN label(n) AS k, n.value AS v
$$) AS (k text, v text);
It breaks because label(n) doesn't exist since f doesn't exist in the dataset so it's a non-existent key in the json output.
I tried putting a WHERE clause after UNWIND but apparently that isn't proper syntax according to the parser.