Using a json flatten to build results, rather than doing it manually