Postgre SQL - PLV8 functions to query complex json datatype