Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

One small but really convenient tip missing from the article is object shortcuts - these two commands are the same:

    curl -s https://api.github.com/repos/stedolan/jq/issues?per_page=2 | jq '[ .[] | { title: .title, number: .number } ]'
    curl -s https://api.github.com/repos/stedolan/jq/issues?per_page=2 | jq '[ .[] | { title, number } ]'


Not to distract from your point, but in this specific instance I'd probably use

  map({title, number})
instead

  [ .[] | <something> ]


Side note, but one of the hardest things about jq is to realize all the operators operate on streams of values.

For example, map() operates on a stream of arrays. That kind of doubling of iteration can be confusing at first.


The first is nice because it highlights being able to remap the value to different key.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: