Refactor json string generation