Refactoring - broke out json formatting to separate function