Skip to content

Instantly share code, notes, and snippets.

@guilhermecomum
Last active July 2, 2020 23:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save guilhermecomum/cbaa45980e8dffa78451edaaeafb12de to your computer and use it in GitHub Desktop.
Save guilhermecomum/cbaa45980e8dffa78451edaaeafb12de to your computer and use it in GitHub Desktop.
Google Spreadsheet to JSON
const data = require("./googlespreadsheet.json");
var columns = [];
var rows = {};
for (var i = 0; i < data.feed.entry.length; i++) {
var entry = data.feed.entry[i];
var value = entry.content.$t;
var row = entry["gs$cell"]["row"];
var col = entry["gs$cell"]["col"];
var key = columns[col - 1];
var newRow = {};
if (entry["gs$cell"]["row"] === "1") {
columns.push(value);
} else {
rows[row] = { ...rows[row], [key]: value };
}
}
rows = Object.values(rows);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment