Creating dummy from JSON values and using it in the WHERE clause
I've conceived an unelegant but working approach using a subquery:

SELECT COUNT(*) as has_defaulted

FROM (
SELECT answer::json-&gt;&gt;'value' AS resp
_FROM CLAUSE HERE_
WHERE CONDITION 1
  AND "code" = 'hasDefaulted' ) as subquery
  GROUP BY subquery.resp
  ORDER BY subquery.resp ASC
  LIMIT 1)