Created
October 11, 2018 01:05
-
-
Save bretcj7/c59b041b95aa8dab13fa983f672d619e to your computer and use it in GitHub Desktop.
slice hash
This file contains 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
Only extract: Name, Owner's login, html_url and score | |
The nested part of Owner got me. | |
{code} | |
keys_to_extract = ['name', 'html_url', 'stargazers_count'] | |
json_trimmed = json['items'].map do |v| | |
v.select { |k, _| keys_to_extract.include? k } | |
#v.dig('owner', 'login') | |
end | |
example hash: | |
{ | |
"total_count": 1546451, | |
"incomplete_results": false, | |
"items": [ | |
{ | |
"id": 8514, | |
"node_id": "MDEwOlJlcG9zaXRvcnk4NTE0", | |
"name": "rails", | |
"owner": { | |
"login": "rails", | |
"id": 4223 | |
}, | |
"html_url": "https://github.com/rails/rails", | |
"description": "Ruby on Rails", | |
"fork": false, | |
"score": 1.0 | |
}, | |
{ | |
"id": 8514, | |
"node_id": "MDEwOlJlcG9zaXRvcnk4NTE0", | |
"name": "rails", | |
"owner": { | |
"login": "rails", | |
"id": 4223 | |
}, | |
"html_url": "https://github.com/rails/rails", | |
"description": "Ruby on Rails", | |
"fork": false, | |
"score": 1.0 | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment