Output Formats
Four output formats for every list and get command — table, JSON, CSV, and XML. Set defaults, pipe to jq, export to spreadsheets.
Every list and get command supports four output formats via the --output flag (short: -o). The default is table — a human-readable ASCII table. Switch to json, csv, or xml for scripting, spreadsheets, or enterprise integration.
megaport-cli locations list --output table # default
megaport-cli locations list --output json
megaport-cli locations list --output csv
megaport-cli locations list --output xml
Table (default)
Human-readable columns. Best for browsing resources interactively in the terminal. Use when: you're exploring, demoing, or quickly checking resource status.
megaport-cli locations list --metro Sydney --output table
NAME COUNTRY METRO STATUS MCR AVAILABLE
NextDC S1 Sydney Australia Sydney ACTIVE true
Equinix SY3 Sydney Australia Sydney ACTIVE true
Equinix SY4 Sydney Australia Sydney ACTIVE false
Global Switch Sydney West Australia Sydney ACTIVE true
NEXTDC S2 Sydney Australia Sydney ACTIVE true
JSON
Machine-readable JSON array. Best for scripting, automation, and piping to jq.
megaport-cli locations list --metro Sydney --output json
[
{
"id": 3,
"name": "NextDC S1 Sydney",
"country": "Australia",
"metro": "Sydney",
"market": "AU",
"status": "ACTIVE",
"mcrAvailable": true,
"mveAvailable": true
},
{
"id": 6,
"name": "Equinix SY3 Sydney",
"country": "Australia",
"metro": "Sydney",
"market": "AU",
"status": "ACTIVE",
"mcrAvailable": true,
"mveAvailable": false
}
]
Filtering with jq
JSON output is designed for jq pipelines:
# Extract just location names
megaport-cli locations list --output json | jq '.[] | .name'
# Filter to only MCR-capable locations
megaport-cli locations list --output json | jq '[.[] | select(.mcrAvailable == true)]'
# Get IDs and names as a compact list
megaport-cli locations list --metro Sydney --output json | jq '[.[] | {id, name}]'
# Count results
megaport-cli locations list --country AU --output json | jq 'length'
# Extract a field from a single resource
megaport-cli ports get <UID> --output json | jq '.status'
For Sales demos
Show customers the JSON output to immediately demonstrate automation readiness. The structured output makes it obvious the CLI is built for scripting, CI/CD, and IaC pipelines — not just human use.
CSV
Comma-separated values with a header row. Use when: you need to share data with non-technical stakeholders, import into Excel/Google Sheets, feed into data pipelines, or generate monthly resource reports for finance teams.
megaport-cli locations list --metro Sydney --output csv
ID,NAME,COUNTRY,METRO,STATUS,MCR_AVAILABLE,MVE_AVAILABLE
3,NextDC S1 Sydney,Australia,Sydney,ACTIVE,true,true
6,Equinix SY3 Sydney,Australia,Sydney,ACTIVE,true,false
7,Equinix SY4 Sydney,Australia,Sydney,ACTIVE,false,false
Saving to file
# Export your ports to a spreadsheet
megaport-cli ports list --output csv > my-ports.csv
# Export all AU locations
megaport-cli locations list --country AU --output csv > au-locations.csv
# Monthly snapshot of all resources
megaport-cli ports list --output csv > ports.csv
megaport-cli mcr list --output csv > mcrs.csv
megaport-cli mve list --output csv > mves.csv
XML
XML with standard encoding header. Use when: integrating with legacy enterprise systems, SOAP-based workflows, or monitoring tools that consume XML feeds (e.g. ServiceNow, BMC, some ITSM platforms).
megaport-cli locations list --metro Sydney --output xml
<?xml version="1.0" encoding="UTF-8"?>
<locations>
<location>
<id>3</id>
<name>NextDC S1 Sydney</name>
<country>Australia</country>
<metro>Sydney</metro>
<status>ACTIVE</status>
<mcrAvailable>true</mcrAvailable>
<mveAvailable>true</mveAvailable>
</location>
<location>
<id>6</id>
<name>Equinix SY3 Sydney</name>
<country>Australia</country>
<metro>Sydney</metro>
<status>ACTIVE</status>
<mcrAvailable>true</mcrAvailable>
<mveAvailable>false</mveAvailable>
</location>
</locations>
Filtering output with --fields and --query
Two global flags give you fine-grained control over output without external tools like jq:
Select specific fields
Use --fields to limit output to a comma-separated list of columns:
# Show only name and status
megaport-cli ports list --fields name,provisioningStatus
# Combine with any output format
megaport-cli locations list --metro Sydney --fields id,name,mcrAvailable --output csv
JMESPath queries
Use --query with --output json to apply JMESPath expressions directly:
# Get names of all LIVE ports
megaport-cli ports list --output json --query "[?provisioningStatus=='LIVE'].name"
# Get location IDs where MCR is available
megaport-cli locations list --output json --query "[?mcrAvailable].id"
--query is a built-in alternative to piping through jq — useful when jq isn't installed or in CI environments.
Set a default format
If you prefer a format other than table, set it as the default so you don't have to specify it on every command:
# Default to JSON for all commands
megaport-cli config set-default output json
# Verify
megaport-cli config get-default output
# json
# Now all commands return JSON without --output
megaport-cli locations list --metro Sydney
# Remove the default (revert to table)
megaport-cli config remove-default output
Format comparison
| Format | Flag | Best for |
|---|---|---|
table | --output table (default) | Terminal browsing, human review |
json | --output json | Scripting, jq, automation, APIs |
csv | --output csv | Excel, Google Sheets, data tools |
xml | --output xml | Enterprise systems, legacy integration |
What's next?
- Config Profiles — set output defaults and manage environments
- First Commands — where output formats were first introduced