Handling for generating and outputting JSON.