> For the complete documentation index, see [llms.txt](https://docs.console.zenlayer.com/zenlayer-cli/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.console.zenlayer.com/zenlayer-cli/usage/output.md).

# Output Formats

This guide introduces the different output formats supported by Zenlayer Cloud CLI and how to use them.

## Output Formats Overview

Zenlayer Cloud CLI supports the following output formats:

* **json** - Output formatted as a JSON string. This is the default output format, suitable for programmatic processing and automation scripts.
* **table** - Output formatted as a table using characters +|- to form cell borders. It typically presents information in a "human-friendly" format that is more readable than other formats but less useful for programming.

## How to Choose an Output Format

You can specify the output format in three ways:

### 1. Set in Configuration File

You can use the output option in a named profile in the configuration file:

```json
{
  "default": {
    "output": "json"  // or "table"
  }
}
```

### 2. Use Environment Variables

You can set the output format using environment variables:

```bash
# Linux/macOS
export ZENLAYER_OUTPUT=table

# Windows
set ZENLAYER_OUTPUT=table
```

Using environment variables overrides values set in the configuration file.

### 3. Use Command Line Parameters

You can specify the output format using the `--output` or `-o` parameter in a command:

```bash
# Use JSON format
zeno zec describe-instances --output json

# Use table format
zeno zec describe-instances --output table

# Use shorthand
zeno zec describe-instances -o table
```

Using this option on the command line overrides any currently set environment variable or configuration file values.

## JSON Output Format

JSON is the default output format for Zenlayer Cloud CLI. Most programming languages can easily decode JSON strings using built-in functions or publicly available libraries. You can combine JSON output with the `--query` option to powerfully filter and format Zenlayer Cloud CLI's JSON-formatted output.

For more advanced filtering that may not be achievable with `--query`, you can consider using `jq`, a command-line JSON processor. You can download it and find the official tutorial at <http://stedolan.github.io/jq/>.

### Example Output

```json
{
  "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
  "dataSet": [
    {
      "instanceId": "ins-xxxxxxxx",
      "name": "my-instance",
      "zoneId": "asia-east-1a",
      "status": "RUNNING",
      "instanceType": "zec.s1.small"
    },
    {
      "instanceId": "ins-yyyyyyyy",
      "name": "test-instance",
      "zoneId": "asia-south-1a",
      "status": "RUNNING",
      "instanceType": "zec.s2.medium"
    }
  ]
}
```

### Use Cases

* **Automation Scripts**: JSON format is easy to parse and process by scripts
* **API Integration**: JSON format can be used directly for API calls
* **Data Transfer**: JSON format is suitable for transferring data between systems

## Table Format

Table format outputs data in tabular form, suitable for human reading and quick viewing.

### Example Output

```
----------------------------------------------------------------------------------------------------
+----------------------+---------------------------------------------------------------------------+
|  requestId           |  T253B0E0E-42D5-45ED-A441-922429A90E68                                    |
+----------------------+---------------------------------------------------------------------------+
||                                            zoneSet                                             ||
|+------------------+-----------------------+-----------+--------------------+--------------------+|
||     regionId     | supportSecurityGroup  | timeZone  |       zoneId       |      zoneName      ||
|+------------------+-----------------------+-----------+--------------------+--------------------+|
||  asia-east-1     |  true                 |           |  SH1A              |  asia-east-1a      ||
||  europe-central-1|  true                 |           |  europe-central-1a |  europe-central-1a ||
|+------------------+-----------------------+-----------+--------------------+--------------------+|
```

### Use Cases

* **Manual Operations**: Table format is easy for humans to read
* **Quick Overview**: Table format provides a quick overview of data
* **Command Line Interaction**: Table format is suitable for viewing in the terminal

## Filtering Output with Queries

Zenlayer Cloud CLI supports using the JMESPath query language to filter and transform output. You can specify query expressions using the `--query` or `-q` parameter.

### Basic Queries

#### Extracting Specific Fields

```bash
# Extract all instance IDs
zeno zec describe-instances --query "dataSet[*].instanceId"
```

Output:

```json
[
  "123456xxxx",
  "789012xxxx"
]
```

#### Filtering Data

```bash
# Filter instances with running status
zeno zec describe-instances --query "dataSet[?status=='RUNNING']"
```

#### Nested Queries

```bash
# Extract nested fields
zeno zec describe-instances --query "dataSet[*].{ID: instanceId, Name: name}"
```

Output:

```json
[
  {
    "ID": "123456xxx",
    "Name": "my-instance"
  },
  {
    "ID": "789012xxxx",
    "Name": "test-instance"
  }
]
```

### JMESPath Syntax

JMESPath supports the following syntax:

* **Dot Notation**: `foo.bar` - Access nested fields
* **Array Index**: `foo[0]` - Access the first element of an array
* **Wildcard**: `foo[*]` - Access all elements of an array
* **Filter Expression**: `foo[?bar=='baz']` - Filter array elements
* **Projection**: `foo[*].bar` - Extract the bar field from each element in the array
* **Pipe**: `foo | bar` - Use the result of the left side as input for the right side

### Example: Complex Query

```bash
# Extract instance names in asia-east-1a zone with running status
zeno zec describe-instances --query "dataSet[?zoneId=='asia-east-1a' && status=='RUNNING'].name"
```

## Pagination

For list commands that support `--page-num` and `--page-size`, the CLI fetches only a single page by default. Use `--page-all` to automatically iterate through every page and merge all results into one response.

```bash
zeno zec describe-instances --page-all
```

See [Pagination](/zenlayer-cli/usage/pagination.md) for full details on manual and automatic pagination.

## Output Format Best Practices

* **Choose format based on use case**:
  * Use JSON format for programmatic processing
  * Use Table format for human reading
* **Use query filtering**: Use the `--query` option to filter output and get only the information you need
* **Combine output format and queries**: Combine output formats and queries as needed
* **Save output**: Save output to files for subsequent processing

### Example: Saving Output to a File

```bash
# Save JSON format output to a file
zeno zec describe-instances --output json > instances.json

# Save table format output to a file
zeno zec describe-instances --output table > instances.txt
```

## FAQ

### Output Format Not Taking Effect

If the output format is not taking effect, check:

* Whether the output format is correctly specified
* Command-line parameters take precedence over environment variables and configuration files
* Whether the CLI is the latest version

### Query Expression Errors

If there are query expression errors, check:

* Whether the JMESPath syntax is correct
* Whether the query path matches the API response structure
* Whether quoting is correct

### Output Truncated

If the output is truncated, it may be because:

* The output content is too large
* Terminal width limitations
* You can use `--output json` to get the complete output

## Related Documentation

* [Command Structure](/zenlayer-cli/usage/command-structure.md) - Learn about the basic structure of CLI commands
* [Parameter Types](/zenlayer-cli/usage/parameter-types.md) - Learn about different parameter type usage


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.console.zenlayer.com/zenlayer-cli/usage/output.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
