Skip to content

feat: add --fields to project top-level response fields across all formats#286

Open
jongio wants to merge 1 commit into
mainfrom
idea/fields-projection
Open

feat: add --fields to project top-level response fields across all formats#286
jongio wants to merge 1 commit into
mainfrom
idea/fields-projection

Conversation

@jongio

@jongio jongio commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Adds --fields to keep only the listed top-level fields of a JSON response. Closes #281.

What it does

Trims a response to a few fields without writing a JMESPath projection that depends on the response shape.

  • Runs before formatting, so it applies to json, table, csv, and yaml and to any downstream pipe (unlike --table-columns, which only affects table rendering).
  • Handles three shapes: a single object keeps the listed keys, an array of objects trims each element, and an ARM value[] wrapper trims each value element while keeping the wrapper so paging links survive.
  • Runs after --query, so you can narrow the response first, then trim.
  • A non-JSON response is left unchanged with a note on stderr.

Example

azd rest GET "$ARM/subscriptions/$SUB/resourceGroups?api-version=2021-04-01" \
  --fields name,location --format table

Tests

  • Unit: object trim, array trim, ARM value[] wrapper keeps nextLink, missing field omitted, non-JSON returns unchanged.
  • Execute-level: trims json output, applies to csv format, non-JSON left unchanged.

All Go gates pass locally (build, tests, golangci-lint, gosec, govulncheck, deadcode, cspell).

Add a --fields flag that keeps only the listed top-level fields of a
JSON response, so you can trim output without writing a JMESPath
projection that depends on the response shape.

Unlike --table-columns, which only affects table rendering, --fields
runs before formatting and applies across every output format (json,
table, csv, yaml) and any downstream pipe. It handles three shapes: a
single object keeps the listed keys, an array of objects trims each
element, and an ARM value[] wrapper trims each value element while
keeping the wrapper so paging links survive.

It runs after --query, so you can narrow the response first and then
trim the fields. A non-JSON response is left unchanged with a note on
stderr.

Closes #281

Co-authored-by: Copilot App <[email protected]>
@jongio jongio added the idea Feature idea from the idea pipeline label Jul 13, 2026
@jongio jongio self-assigned this Jul 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Website Preview

Your PR preview is ready!

📎 Preview URL: https://jongio.github.io/azd-rest/pr/286/

This preview will be automatically cleaned up when the PR is closed.

github-actions Bot added a commit that referenced this pull request Jul 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Test This PR

A preview build (0.5.0-pr286) is ready for testing!

One-Line Install (Recommended)

PowerShell (Windows):

iex "& { $(irm https://raw.githubusercontent.com/jongio/azd-rest/main/scripts/install-pr.ps1) } -PrNumber 286 -Version 0.5.0-pr286"

Bash (macOS/Linux):

curl -fsSL https://raw.githubusercontent.com/jongio/azd-rest/main/scripts/install-pr.sh | bash -s 286 0.5.0-pr286

Uninstall

PowerShell (Windows):

iex "& { $(irm https://raw.githubusercontent.com/jongio/azd-rest/main/scripts/uninstall-pr.ps1) } -PrNumber 286"

Bash (macOS/Linux):

curl -fsSL https://raw.githubusercontent.com/jongio/azd-rest/main/scripts/uninstall-pr.sh | bash -s 286

Build Info:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

idea Feature idea from the idea pipeline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add --fields to project top-level response fields across all formats

1 participant