Skip to content

Instantly share code, notes, and snippets.

@payne
Forked from bradmontgomery/shell.sh
Last active August 29, 2015 14:06
Show Gist options
  • Save payne/985d2d017ae38ac717a6 to your computer and use it in GitHub Desktop.
Save payne/985d2d017ae38ac717a6 to your computer and use it in GitHub Desktop.
# pretty-print a JSON result
curl 'https://graph.facebook.com/memphispython/albums/' | jq '.'
# grab the data list
curl 'https://graph.facebook.com/memphispython/albums/' | jq '.data'
# Get *just* the first album
curl 'https://graph.facebook.com/memphispython/albums/' | jq '.data[0]'
# Narrow that first entry to some specific data
curl 'https://graph.facebook.com/memphispython/albums/' | jq '.data[0] | {name, location, link}'
# List just name & link for all albums
curl 'https://graph.facebook.com/memphispython/albums/' | jq '.data[] | {name, link}'
# "collect" the above data in a list
curl 'https://graph.facebook.com/memphispython/albums/' | jq '[.data[] | {name, link}]'
# don't forget to save it to another file.
curl 'https://graph.facebook.com/memphispython/albums/' | jq '[.data[] | {name, link}]' > albums.json
# OR, flatten the whole result into a list of album names
curl 'https://graph.facebook.com/memphispython/albums/' | jq '[.data[] | .name]'
# Look at who liked albums
curl 'https://graph.facebook.com/memphispython/albums/' | jq '.data[] | .likes | .data[]'
# Flatten the list of names that liked our albums (note: there's duplicates and errors about nulls)
curl 'https://graph.facebook.com/memphispython/albums/' | jq '.data[] | .likes | [.data[] | .name][]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment