Add -json output mode for shell

Implement #523, --json for the shell.