added json generation
Honor the JSON flag.