Skip to content

feat: add --omit to remove JSON response fields#303

Open
jongio wants to merge 1 commit into
mainfrom
idea/omit-flag
Open

feat: add --omit to remove JSON response fields#303
jongio wants to merge 1 commit into
mainfrom
idea/omit-flag

Conversation

@jongio

@jongio jongio commented Jul 19, 2026

Copy link
Copy Markdown
Owner

What

Adds a repeatable --omit <dotted-path> flag that removes fields from a JSON response before it is printed or written to --output-file.

It is the structural complement to --redact: redaction masks a value in place, omission drops the key (or every element of a matched array) so the field no longer appears in the output.

Why

--redact can hide a value, but the key stays in the payload. When you want a smaller, cleaner response for a script, a diff, or a snapshot, you need the field gone, not masked. --omit fills that gap and reuses the same dotted-path syntax people already know from --redact.

How

  • New --omit persistent flag (repeatable) wired through config.Config.Omit and the config snapshot, mirroring --redact.
  • omitJSONBody parses the body with UseNumber, walks each dotted path, and re-encodes. It reuses splitRedactPath from the redact path walker, where * matches every array element.
  • Applied in writeResponseOutput right after the redact step and before flatten, so the ordering is mask then delete then reshape.
  • Raw and binary output cannot be parsed as JSON, so it is left unchanged with a note on stderr. A path that matches nothing is a safe no-op.

Examples

# Drop a noisy field from every item of an ARM list response
azd rest get "https://management.azure.com/subscriptions/{sub}/resourceGroups?api-version=2021-04-01" \
  --omit value.*.properties.provisioningState

# Remove several fields at once
azd rest get "https://management.azure.com/subscriptions/{sub}?api-version=2022-12-01" \
  --omit tags --omit managedByTenants

Tests

  • 7 new unit tests in omit_test.go: object path, array wildcard, wildcard empties an array, miss is a no-op, numbers preserved, top-level key, invalid JSON returns an error.
  • Full mage test passes; mage build and mage fmt clean.

Docs

  • README example, CLI reference table row plus an "Omitting Response Fields" section, SKILL.md flag row, and the website reference page.

Closes #297

Adds a repeatable --omit flag that removes fields from a JSON response before output, the structural complement to --redact (which masks values in place). Reuses the redact dotted-path walker, where * matches every array element. Runs on the same JSON output paths as redaction; raw and binary output is left unchanged with a note on stderr, and a path that matches nothing is a no-op.

Closes #297

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@jongio jongio added the idea Feature idea from the idea pipeline label Jul 19, 2026
@jongio jongio self-assigned this Jul 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Website Preview

Your PR preview is ready!

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

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

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

Copy link
Copy Markdown
Contributor

🚀 Test This PR

A preview build (0.5.0-pr303) 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 303 -Version 0.5.0-pr303"

Bash (macOS/Linux):

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

Uninstall

PowerShell (Windows):

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

Bash (macOS/Linux):

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

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 --omit to remove fields from a JSON response

1 participant