put the JSON output in a separate function