Skip to content

Instantly share code, notes, and snippets.

@mkwatson
Last active July 16, 2021 17:52
Show Gist options
  • Save mkwatson/b6cf1d56d0c7150e053fa00e47c982d2 to your computer and use it in GitHub Desktop.
Save mkwatson/b6cf1d56d0c7150e053fa00e47c982d2 to your computer and use it in GitHub Desktop.
Search US golf courses with jq
# You might want to download all_course_ratings.json locally first
# QUESTION: What's the jq command to only return the TeeRows for TeeName=White and Gender=Male for a given course?
# Below is the query to return all tee rows for a course, in this case Peacock Gap Golf Club:
curl https://golfcourses.s3.us-west-1.amazonaws.com/all_course_ratings.json | \
jq '
.[] |
select(
(.CourseState == "US-CA") and
(.CourseName | test("Peacock"; "i"))
)
'
# OUTPUT:
# {
# "CourseName": "Peacock Gap GCC",
# "CourseCity": "San Rafael",
# "CourseState": "US-CA",
# "TeeRows": [
# {
# "TeeName": "White",
# "Gender": "Female",
# "Par": 71,
# "CourseRating": 72.2,
# "BogeyRating": 101.8,
# "SlopeRating": 126,
# "Front": "36.4 / 126.0",
# "Back": "35.8 / 126.0"
# },
# {
# "TeeName": "Red",
# "Gender": "Female",
# "Par": 71,
# "CourseRating": 67.9,
# "BogeyRating": 95.4,
# "SlopeRating": 116,
# "Front": "34.1 / 114.0",
# "Back": "33.8 / 118.0"
# },
# {
# "TeeName": "Red/White Combo",
# "Gender": "Female",
# "Par": 71,
# "CourseRating": 70.9,
# "BogeyRating": 99.8,
# "SlopeRating": 123,
# "Front": "36.1 / 125.0",
# "Back": "34.8 / 121.0"
# },
# {
# "TeeName": "Blue",
# "Gender": "Male",
# "Par": 71,
# "CourseRating": 69,
# "BogeyRating": 91.6,
# "SlopeRating": 122,
# "Front": "34.9 / 122.0",
# "Back": "34.1 / 122.0"
# },
# {
# "TeeName": "White",
# "Gender": "Male",
# "Par": 71,
# "CourseRating": 67.2,
# "BogeyRating": 89,
# "SlopeRating": 117,
# "Front": "33.9 / 119.0",
# "Back": "33.3 / 115.0"
# },
# {
# "TeeName": "Black",
# "Gender": "Male",
# "Par": 71,
# "CourseRating": 69.9,
# "BogeyRating": 93.1,
# "SlopeRating": 125,
# "Front": "35.2 / 123.0",
# "Back": "34.7 / 127.0"
# },
# {
# "TeeName": "Red/White Combo",
# "Gender": "Male",
# "Par": 71,
# "CourseRating": 66.4,
# "BogeyRating": 87.4,
# "SlopeRating": 113,
# "Front": "33.9 / 114.0",
# "Back": "32.5 / 112.0"
# },
# {
# "TeeName": "Red",
# "Gender": "Male",
# "Par": 71,
# "CourseRating": 64.3,
# "BogeyRating": 82.7,
# "SlopeRating": 99,
# "Front": "32.4 / 97.0",
# "Back": "31.9 / 101.0"
# },
# {
# "TeeName": "Blue",
# "Gender": "Female",
# "Par": 71,
# "CourseRating": 74.5,
# "BogeyRating": 105.3,
# "SlopeRating": 131,
# "Front": "37.7 / 131.0",
# "Back": "36.8 / 131.0"
# },
# {
# "TeeName": "Black",
# "Gender": "Female",
# "Par": 71,
# "CourseRating": 75.5,
# "BogeyRating": 106.6,
# "SlopeRating": 132,
# "Front": "38.0 / 132.0",
# "Back": "37.5 / 132.0"
# }
# ]
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment