Skip to content

Instantly share code, notes, and snippets.

@liddiard
Last active July 24, 2020 13:45
Show Gist options
  • Save liddiard/01b1a2b6376849b2f89c to your computer and use it in GitHub Desktop.
Save liddiard/01b1a2b6376849b2f89c to your computer and use it in GitHub Desktop.
Make a JSON feed from Google Sheets more pretty to work with – removes "gsx$" key prefixes, un-nests unnecessarily nested objects. Make a GET request to a URL in this format: https://spreadsheets.google.com/feeds/list/126o06NkYz3rLRrIbzKAeLtrK-4a_Eosccmoser11hnk/od6/public/values?alt=json, and pass the resulting JSON to this function.
function prettifyGoogleSheetsJSON(data) {
for (var i = 0; i < data.feed.entry.length; i++) {
for (var key in data.feed.entry[i]) {
if (data.feed.entry[i].hasOwnProperty(key) && key.substr(0,4) === 'gsx$') {
// copy the value in the key up a level and delete the original key
data.feed.entry[i][key.substr(4)] = data.feed.entry[i][key].$t;
delete data.feed.entry[i][key];
}
}
}
return data.feed.entry;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment