Published
Edited
Feb 5, 2021
Insert cell
md`# Parse Google Sheet JSON Feed`
Insert cell
d3 = require('d3-fetch')
Insert cell
data = {
return await d3.json(
'https://spreadsheets.google.com/feeds/cells/1aoNnLeoDj50fbaQY27JJdApW8HSoSRRCF3bHh2xR8uE/1/public/full?alt=json'
);
}
Insert cell
sheet = {
const currSheet = {};
currSheet.dims = [
Number(data.feed.gs$colCount.$t),
Number(data.feed.gs$rowCount.$t)
];
currSheet.rows = data.feed.entry;
currSheet.header = (function() {
let header = [];
for (let i = 0; i < currSheet.dims[0]; i++) {
header.push(currSheet.rows[i].content.$t);
}
return header;
})();

return currSheet;
}
Insert cell
json = {
let rows = [];
for (let i = 2; i <= sheet.dims[1]; i++) {
let row = {};
let cells = sheet.rows.filter(d => d.gs$cell.row == i).map(d => d.gs$cell);
for (let j = 0; j < sheet.dims[0]; j++) {
row[sheet.header[j]] = cells
.filter(d => Number(d.col) == j + 1)
.map(d => d.$t)[0];
}
row['Photos'] = row['Photos'].split(',');
rows.push(row);
}

return rows;
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more