Output formats for Azure CLI 2.0 commands

02/15/2018

3 minutes to read

Contributors

In this article

Azure CLI 2.0 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. This setting is the default.

jsonc

Colorized JSON.

table

ASCII table with keys as column headings.

tsv

Tab-separated values, with no keys

JSON output format

The following example displays the list of virtual machines in your subscriptions in the default json format.

az vm list --output json

The following output has some fields omitted for brevity, and identifying information replaced.

Table output format

The table output format provides plain output formatted as rows and columns of collated data, making it easy to read and scan. Nested objects are not included in table output, but can still be filtered as part of a query. Some fields are also omitted from the table data, so this format is best when you want a quick, human-searchable overview of data.

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 VM Name and the Resource Group Name in the list command.

Certain keys are filtered out and not printed in the table view. These are id, type, and etag. If you need to see these
in your output, you can use the JMESPath re-keying feature to change the key name and avoid filtering.

TSV output format

The tsv output format returns tab- and newline-separated values without additional formatting, keys, or other symbols. This format makes it easy to consume the output into other commands and tools that need to process the text in some form. Like the table format, the tsv output option does not print nested objects.

Using the preceding example with the tsv option outputs the tab-separated result.

The next example shows how the tsv output can be piped to other commands on UNIX systems to extract more specific data. The grep command selects items that have text "RGD" in them, and then the cut command selects the eighth field (separated by tabs) to show the name of the VM in output.

az vm list --out tsv | grep RGD | cut -f8

KBDemo001VM
KBDemo020

For the purposes of processing tab-separated fields, the values are in the same order that they appear in the printed JSON object. This order is guaranteed to be consistent between runs of the command.

Set the default output format

Use the interactive az configure command to set up your environment and establish default settings for output formats. The default output format is json.

az configure

Welcome to the Azure CLI! This command will guide you through logging in and setting some default values.
Your settings can be found at /home/defaultuser/.azure/config
Your current configuration is as follows:
...
Do you wish to change your settings? (y/N): y
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 [1]: