factor out JSON output;add prettyJSON for commandline use
update TS;fixes #21