Skip to content

Instantly share code, notes, and snippets.

@dmahugh
Created March 22, 2016 22:38
Show Gist options
  • Save dmahugh/c45362ef8a74f53f3f6d to your computer and use it in GitHub Desktop.
Save dmahugh/c45362ef8a74f53f3f6d to your computer and use it in GitHub Desktop.
Python function to remove URL bloat from JSON returned by GitHub V3 API
def remove_github_urls(dict_in):
"""Remove URL entries (as returned by GitHub API) from a dictionary.
1st parameter = dictionary
Returns a copy of the dictionary, but with no entries named *_url or url.
"""
return {key: dict_in[key] for key in dict_in if \
not key.endswith('_url') and not key == 'url'}
@dmahugh
Copy link
Author

dmahugh commented Mar 22, 2016

The JSON returned by most calls to the GitHub V3 API is an order of magnitude larger than it needs to be, because it contains all of the endpoints for other related queries you might want to do next. This one-liner uses a Python dictionary comprehension to get rid of all that extra stuff.

bloatedgithubapi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment