You could send this to a transformer as per this post's suggestion to filter/parse the data with JS map/filters:
This also seems to be somewhat achievable using the ARRAY function in AlaSQL but you might have to join two separate queries to get the results you want.