gh formatting

Formatting options for JSON data exported from gh


Some gh commands support exporting the data as JSON as an alternative to their usual line-based plain text output. This is suitable for passing structured data to scripts. The JSON output is enabled with the --json option, followed by the list of fields to fetch. Use the flag without a value to get the list of available fields.

The --jq option accepts a query in jq syntax and will print only the resulting values that match the query. This is equivalent to piping the output to jq -r, but does not require the jq utility to be installed on the system. To learn more about the query syntax, see:

With --template, the provided Go template is rendered using the JSON data as input. For the syntax of Go templates, see:

The following functions are available in templates:

  • color <style>, <input>: colorize input using
  • autocolor: like color, but only emits color to terminals
  • timefmt <format> <time>: formats a timestamp using Go's Time.Format function
  • timeago <time>: renders a timestamp as relative to now
  • pluck <field> <list>: collects values of a field from all items in the input
  • join <sep> <list>: joins values in the list using a separator

Options inherited from parent commands

      --help   Show help for command