Add a flag to control output format (JSON or protobuf)

Fixed #179.