Refactor the JSON to HTML code into a method.