Skip to content

Allow --jq and --template to be used together in gh api #10261

Closed as duplicate

Description

@0xdevalias

Describe the feature or problem you’d like to solve

When using gh api, I would like to be able to use the expressive power of --jq to manipulate/filter the JSON response data, and then --template to render it, but currently that doesn't seem to be allowed:

Proposed solution

If it were possible to pass both --jq and --template together, then users would have more expressive ability to manipulate API response data through gh api without having to resort to moving to external tools/processing.

In particular, this would allow users to use --jq's deeper functionality for manipulation, while leveraging --template's simple/clean syntax for rendering the output.

Additional context

See also:

Activity

  1. 0xdevalias commented on Jan 17, 2025

    @0xdevalias
    Author

    Another potentially useful feature/workaround/alternative (which I haven't checked too deeply to see if it is currently possible), would being able to pipe arbitrary json to the gh CLI, and then process that with --template. That would then allow us to do something like:

    gh api --jq '.' FOO | some_external_processing_filter | gh json --template 'BAR'
  2. 0xdevalias commented on Jan 17, 2025

    @0xdevalias
    Author

    You can see a real world example of why it would be nice to combine --jq with --template in #659 (comment)

  3. self-assigned this
    on Jan 17, 2025
  4. BagToad commented on Jan 17, 2025

    @BagToad
    Member

    👋 Hey @0xdevalias - thanks for this!

    I think this may be a duplicate of:

    There seems to be some workarounds discussed already in that thread - I highlighted what I thought was the most applicable below.


    Another potentially useful feature/workaround/alternative (which I haven't checked too deeply to see if it is currently possible), would being able to pipe arbitrary json to the gh CLI, and then process that with --template. That would then allow us to do something like:

    gh api --jq '.' FOO | some_external_processing_filter | gh json --template 'BAR'

    From #8415, I suspect https://github.com/heaths/gh-merge-json may be what you're looking for 😁

    Please let me know if I misunderstood and we can re-open this issue ❤

  5. added
    duplicatethis is already captured in another issue
    and removed on Jan 17, 2025
  6. removed their assignment
    on Jan 17, 2025
  7. 0xdevalias commented on Jan 18, 2025

    @0xdevalias
    Author

    I think this may be a duplicate of:

    @BagToad I haven't read the full thread yet, so I may have missed something, but at least from reading the main post, it sounds like they want to be able to get the --jq and --template output separately. Whereas I want the --jq processing to happen, and then the --template to be applied to that processed json, outputting only the final --template result.

    Though I guess reading further, it sounds like it does coalesce to what I am requesting here.. so yeah, that should be fine :)

    (Though I wonder if that nuance might be able to be added to the title, or the first post or similar; as I would have bypassed it completely based on the title/original post content)


    From #8415, I suspect heaths/gh-merge-json may be what you're looking for 😁

    @BagToad That definitely sounds like it will do the trick for that need. Thanks :)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicatethis is already captured in another issueenhancementa request to improve CLI

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions