Change:
} cmd.Flags().BoolP("client", "c", false, "Client version only (no server required).") cmd.Flags().BoolP("short", "", false, "Print just the version number.") <ins> cmd.Flags().String("output", "", "output format, options available are yaml and json") </ins> cmd.Flags().MarkShorthandDeprecated("client", "please use --client instead.") return cmd } func RunVersion(f cmdutil.Factory, out io.Writer, cmd *cobra.Command) error { <del> v := fmt.Sprintf("%#v", version.Get()) if cmdutil.GetFlagBool(cmd, "short") { v = version.Get().GitVersion </del> <ins> var serverVersion *apimachineryversion.Info = nil var serverErr error = nil vo := Version{nil, nil} clientVersion := version.Get() vo.ClientVersion = &clientVersion if !cmdutil.GetFlagBool(cmd, "client") { serverVersion, serverErr = retrieveServerVersion(f) vo.ServerVersion = serverVersion </ins> } <del> fmt.Fprintf(out, "Client Version: %sn", v) if cmdutil.GetFlagBool(cmd, "client") { return nil </del> <ins> switch of := cmdutil.GetFlagString(cmd, "output"); of { case "": if cmdutil.GetFlagBool(cmd, "short") { fmt.Fprintf(out, "Client Version: %sn", clientVersion.GitVersion) if serverVersion != nil { fmt.Fprintf(out, "Server Version: %sn", serverVersion.GitVersion) } } else { fmt.Fprintf(out, "Client Version: %sn", fmt.Sprintf("%#v", clientVersion)) if serverVersion != nil { fmt.Fprintf(out, "Server Version: %sn", fmt.Sprintf("%#v", *serverVersion)) } } case "yaml": y, err := yaml.Marshal(&vo) if err != nil { return err } fmt.Fprintln(out, string(y)) case "json": y, err := json.Marshal(&vo) if err != nil { return err } fmt.Fprintln(out, string(y)) default: return errors.New("invalid output format: " + of) </ins> } <del> discoveryclient, err := f.DiscoveryClient() if err != nil { return err </del> <ins> if serverErr != nil { return serverErr </ins> } <del> serverVersion, err := discoveryclient.ServerVersion() </del> <ins> return nil } func retrieveServerVersion(f cmdutil.Factory) (*apimachineryversion.Info, error) { discoveryClient, err := f.DiscoveryClient() </ins> if err != nil { <del> return err </del> <ins> return nil, err </ins> } <del> v = fmt.Sprintf("%#v", *serverVersion) if cmdutil.GetFlagBool(cmd, "short") { v = serverVersion.GitVersion </del> <ins> serverVersion, err := discoveryClient.ServerVersion() if err != nil { return nil, err </ins> } <del> fmt.Fprintf(out, "Server Version: %sn", v) return nil </del> <ins> return serverVersion, nil </ins> }

Discussion:
<!-- Thanks for filing an issue! Before hitting the button, please answer these questions.--Is this a request for help? (If yes, you should use our troubleshooting guide and community support channels, see ): no What keywords did you search in Kubernetes issues before filing this one? (If you have found any duplicates, you should instead reply there.): "kubectl version", "kubectl version" json Is this a BUG REPORT or FEATURE REQUEST? (choose one): Feature request Kubernetes version (use ): $ kubectl version --client Client Version: version.Info{Major:"1", Minor:"4", GitVersion:"v1.4.6", GitCommit:"", GitTreeState:"clean", BuildDate:"2016-11-12T05:22:15Z", GoVersion:"go1.7.1", Compiler:"gc", Platform:"darwin/amd64"} Environment: Cloud provider or hardware configuration: GKE OS (e.g. from /etc/os-release): MacOS 10.12.2 I find it difficult to parse the output of programmatically. I have to use a YAML parser to do it. I'd prefer to use JSON, or to be given just the string and asked to parse it with a regex. This is obviously a relatively low-priority request.
I wouldnt mind helping out on this, if there are no objections?
are you working on this? If not, I would like to work on it.
I plan to, but if i'll keep you posted if i get too delayed.
How can I direct message you?
didnt see this till now, felt bad i had not kept up on this so i decided to just push through it. If my email is not available in my profile, please let me know, otherwise AT gmail would be the best way to contact me.
Thanks!
Included below are some examples. Let me know what you think, my only concern is the the original output of included the key and then the object type which is a little strange. Note the output flag is optional so we don't break previous behavior and contract, which is now baked and part of e2e testing. here are the couple of samples: