Skip to content

Built-in structured output parser for CLI commands #700

@bixu

Description

@bixu

Problem

When working with swamp model data from the CLI, structured output often needs post-processing — parsing JSON responses, extracting fields, filtering arrays. Currently users reach for python3 -c "import sys,json; ..." or jq one-liners piped after --json output, which is clunky and creates a dependency on external tools.

This comes up constantly when:

  • Inspecting model data attributes from swamp data get
  • Filtering output from swamp data list
  • Extracting specific fields from swamp model method run results
  • Chaining CLI commands where one step's output feeds the next

Proposed Solution

Ship a lightweight query/filter mechanism built into the swamp CLI itself. Options:

  1. --query / -q flag on commands that emit JSON — a small expression language (CEL subset, jq-like path syntax, or JSONPath) to extract/filter fields inline. e.g.:

    • swamp data get dev-vms latest --json -q '.attributes.vms[].domain'
    • swamp data list dev-vms --json -q '.groups[].items[] | select(.name | contains("controller"))'
  2. swamp query subcommand that reads JSON from stdin and applies an expression, so it can be piped:

    • swamp model method run dev-vms discover --json | swamp query '.data.attributes.vms | length'
  3. Built-in --format templates for common extractions (table, csv, specific fields).

Since swamp already has a CEL evaluator for workflow expressions, reusing that for CLI output queries would be a natural fit and avoid adding a new expression language.

Alternatives

  • Require users to install jq (common but not universal, especially on CI)
  • Keep relying on python3 -c one-liners (verbose, error-prone)
  • Do nothing (status quo works but adds friction to every CLI interaction)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestexternalAn issue raised by an external contributor

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions