Output formats for VSTS CLI commands

The VSTS CLI uses JSON as its default output option, but offers various ways for you to format the output of any command. Use the --output (or --out or -o) parameter to format the output of the command into one of the output types noted in the following table.

--output Description
json json string. json is the default.
jsonc colorized json string.
table table with column headings.
tsv tab-separated values.

Using the json option

The following example displays the list of pull requests assigned to you in the default JSON format.

vsts code pr list --reviewer alias --output json

The results are in this form (only showing partial output for sake of brevity).

[
  {
    "artifactId": null,
    "autoCompleteSetBy": null,
    "closedBy": null,
    "closedDate": null,
    "codeReviewId": 1,
    "commits": null,
    "completionOptions": null,
    "completionQueueTime": null,
    "createdBy": {
      "directoryAlias": null,
      "displayName": "Fabrikam Fiber",
      "id": "1234fab1-1234-1234-1234-fabrikam1234",
      "imageUrl": "https://fabrikam-fiber-cli.visualstudio.com/_api/_common/identityImage?id=1234fab1-1234-1234-1234-fabrikam1234",
      "inactive": null,
      "isAadIdentity": null,
      "isContainer": null,
      "profileUrl": null,
      "uniqueName": "fabrikam@contoso.com"
  }
]

Using the table option

The table option provides an easy-to-read set of output, but note that nested objects are not included in the output with the simple --output table, unlike the preceding .json example. Using the same example with the table output format provides a curated list of the most common property values.

vsts code pr list --reviewer alias --output table
ID      Created     Creator                 Title                    Status     Repository
------  ----------  ----------------------  -----------------------  --------  --------------------
270621  2017-10-19  fabrikam@contoso.com     fabrikam/update-repo    Active     Demos

You can use the --query parameter to customize the properties and columns you want to show in the list output. The following example shows how to select just the reviewers of an active pull request using the JMESPath query language.

vsts code pr list --status active --query [].reviewers[].displayName
Result
-------------------------------------------------------------
[Demos]\CLI Team
[Demos]\Demo Team
Fabrikam Fiber

Using the tsv option

tsv output format returns a simple text-based and tab-separated output with no headings and dashes. This format makes it easy to consume the output into other commands and tools that need to process the text in some form. Using the preceding example with the tsv option outputs the tab-separated result.

vsts code pr list --reviewer alias --output tsv
None    None    None    None    1       None    None    None            2017-10-30T18:50:18.086685+00:00        None    None    None                            None    None    859b58ee-0e90-4a06-acce-e199823741b6 None    succeeded       1       None            2       refs/heads/fabrikam/update-repo   active  True    refs/heads/master       Merge fabrikam/update-repo to master      https://fabrikam-fiber-cli.visualstudio.com/_apis/git/repositories/b2cfc2a9-499f-41af-b2ae-f4aedade5e9e/pullRequests/1   None

Setting the default output format

You can use the vsts configure command to set up your environment or establish preferences such as default settings for output formats. For common use, the easiest output format default is the table format - select 3 when prompted for output format choices.

What default output format would you like?
 [1] json - JSON formatted output that most closely matches API responses
 [2] jsonc - Colored JSON formatted output that most closely matches API responses
 [3] table - Human-readable output format
 [4] tsv - Tab and Newline delimited, great for GREP, AWK, etc.
Please enter a choice [3]: