Move json generation into own class so it can be reused elsewhere