Little oddity with the built-in --jq flag #6654
-
jq locally installed (:white_check_mark: works as expected)Below a query to get the # jq - commandline JSON processor [version 1.6]
gh api graphql --raw-field query='{ __type(name: "Repository") { fields { name description}}}' |
jq '.data.__type.fields[] | join(" - ")' |
head -3
# "allowUpdateBranch - Whether or not a pull request head branch that is behind its base branch can always be updated even if it is not required to be up to date before merging."
# "assignableUsers - A list of users that can be assigned to issues in this repository."
# "autoMergeAllowed - Whether or not Auto-merge can be enabled on pull requests in this repository." --jq flag ( 🚸 returns fields correctly, but orders them incorrectly)Same query as above, but using the built-in # using the built-in --jq flag
gh api graphql --raw-field query='{ __type(name: "Repository") { fields { name description}}}' \
--jq '.data.__type.fields[] | join(" - ")' |
head -3
# Whether or not a pull request head branch that is behind its base branch can always be updated even if it is not required to be up to date before merging. - allowUpdateBranch
# A list of users that can be assigned to issues in this repository. - assignableUsers
# Whether or not Auto-merge can be enabled on pull requests in this repository. - autoMergeAllowed is it worth opening an issue, or is there a way to get the correct order with the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi, good catch, but this is a difference between jq implementations due to language internals. In Go, maps are always unordered and you cannot rely on some implicit order, or on the other in which keys appear in the original document. The only way to translate the result of a |
Beta Was this translation helpful? Give feedback.
Hi, good catch, but this is a difference between jq implementations due to language internals.
In Go, maps are always unordered and you cannot rely on some implicit order, or on the other in which keys appear in the original document. The only way to translate the result of a
{ name description }
query into something ordered would be to have explicit ordering in your jq query.