Late response but I would like to iterate the previous response. In workflows, always do any complex data manipulation and transformation using the Data Query task which is SQL based data extraction tool. In case you haven't used already try it at Platform->Data query to play with the the query, save it if needed. Its a great, handy tool. Once you have retrieved the what you need, transform using the JSONTransform. If you need to get an ancillary effect on the data then Liquid expressions (Liquid task) can also be beneficial to get the same custom JSON that you are looking for.
... View more