Skip to content

Instantly share code, notes, and snippets.

@lucasinocente
Forked from guilhermecomum/gs2json.js
Created June 30, 2020 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucasinocente/76b32029c76b89d9cd10544fb6bc56f5 to your computer and use it in GitHub Desktop.
Save lucasinocente/76b32029c76b89d9cd10544fb6bc56f5 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