Skip to content

Instantly share code, notes, and snippets.

@karlpokus
Last active February 17, 2016 08:45
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 karlpokus/96746df6aa5968f577e9 to your computer and use it in GitHub Desktop.
Save karlpokus/96746df6aa5968f577e9 to your computer and use it in GitHub Desktop.
Range to json in google sheets
function dataToJSON(data) {
// out
var out= [];
// split
var header = data[0],
body = data.slice(1);
// body LOOP
for (var i = 0; i < body.length; i++) {
//
var o = {};
// header LOOP
for (var j = 0; j < header.length; j++) {
//
o[header[j]] = body[i][j];
}
//
out.push(o);
}
return JSON.stringify(out);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment