Google Sheets is a pretty simple way to make free spreadsheets and to quickly store data. Did you know that you can actually retrieve this data via JSON & JSONP? Here’s how you can do it in just a few easy steps:
- Open the desired Google Spreadsheet.
- Go to File » Publish to the web….
- At the bottom of the Public to the web dialog click and expand the Published content & settings option and then click the Start publishing button and after confirming that you want to publish the document you can close this dialog.
- Pull the Google spreadsheet ID from the URL (eg.
1927NAILJ9_CSkhSYmdxB-kUBN_7Yx6ZN5GXqyK6tKbY
fromhttps://docs.google.com/spreadsheets/d/1927NAILJ9_CSkhSYmdxB-kUBN_7Yx6ZN5GXqyK6tKbY/edit#gid=0
) - Navigate to
https://spreadsheets.google.com/feeds/{{VIEW-TYPE}}/{{SPREADSHEET-ID}}/{{TAB-NUMBER}}/public/values
, replacing{{SPREADSHEET-ID}}
with the spreadsheet ID from the previous step and{{TAB-NUMBER}}
with the number of the tab within the workbook (eg. if it is the first tab you would replace it with1
). - If you would like each cell’s value including the cells in the first row, replace
{{VIEW-TYPE}}
with the wordcells
. If you are fine with the value of each cell within each row being indexed by the corresponding value in the first row, replace{{VIEW-TYPE}}
with the wordlist
. - If you want the output to be JSON you can add
?alt=json
at the end of the URL. If you want the output to be JSONP you will need to add?alt=json-in-script&callback=
followed by the name of the function to which the JSON object will be passed (eg.?json-in-script&callback=myFunc
). - Navigate to this URL to see the JSON representation of your spreadsheet. Here are some working example URLs:
Admittedly this is the old way of retrieving Google Spreadsheet data so this solution may not work forever, but it does for now. Happy coding! š