Output metrics as JSON

This PR adds support for JSON output with `--json` flag.