Created
February 9, 2014 05:22
-
-
Save bradmontgomery/8894685 to your computer and use it in GitHub Desktop.
Playing with `jq`, using the Albums api for a Facebook page. This is loosely based on the tutorial at: http://stedolan.github.io/jq/tutorial/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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