Clicky

iOS Dev Nugget 311 jq

.

Need to run a code review on your codebase? Hire me

As I've done on a few occasions, I also like to drop little nuggets about external tools that aren't specifically for iOS app development, but which can be incredibly useful for.

Check out jq which in the author's own words:

jq is like sed for JSON data - you can use it to slice and filter and map and transform structured data with the same ease that sed, awk, grep and friends let you play with text.

It lets you filter and transform JSON.

An example from the tutorial:

$ curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' | jq '.[] | {message: .commit.message, name: .commit.committer.name}'

The relevant part is:

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

.[] returns each element of the array and pipe them to {message: .commit.message, name: .commit.committer.name}'.

You can count, for example with:

$ curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' | jq '. | length'

Install it with:

brew install jq

Have fun!

Edit 20181007: Fix typo for getting length with the help of @dev_jac.

Your feedback is valuable: Do you want more nuggets like this?   Yes   or   No

.

.

Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter

.

View archives of past issues