Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 582

jq to output results as JSON

$
0
0

jq is suppose to

process/filter JSON inputs and producing the filter's results as JSON

However, I found that after the jq process/filter, output result is no longer in JSON format any more.

E.g., https://stedolan.github.io/jq/tutorial/#result5, i.e.,

$ curl -s 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' | jq '.[] | {message: .commit.message, name: .commit.committer.name}'{"message": "Merge pull request #162 from stedolan/utf8-fixes\n\nUtf8 fixes. Closes #161","name": "Stephen Dolan"}{"message": "Reject all overlong UTF8 sequences.","name": "Stephen Dolan"}. . . 

Is there any workaround?

UPDATE:

How to wrap the whole return into a json structure of:

{ "Commits": [ {...}, {...}, {...} ] }

I've tried:

jq '.[] | Commits: [{message: .commit.message, name: .commit.committer.name}]'jq 'Commits: [.[] | {message: .commit.message, name: .commit.committer.name}]'

but neither works.


Viewing all articles
Browse latest Browse all 582

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>