command/query: Refactor output handling into interface
command/query: Adding support for JSON output