Json output

A small refactoring effort, gevent 1.x DNS workaround and JSON output capability.