Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

266
Views
How can we read file from google sheets url and convert its data into json in vanillaJS/jsquery?

I am working on a project where I need to read a file from google sheets url and then convert its content in json. Then I will use that json object for showing content in the frontend. But I just want to know how can we read an excel file from google sheets url and then are there any built in functions or external library which converts the data in json?

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

To read a spreadsheet via app script and get the json, try (you need to know the id of the spreadsheet and the gid of the sheet)

const readSheet2json = () => {
  var id = '#######';
  var gid = '######';
  var url = `https://docs.google.com/spreadsheets/d/${id}/gviz/tq?tqx=out:json&tq&gid=${gid}`;
  var txt = UrlFetchApp.fetch(url).getContentText();
  var jsonString = txt.slice(47, -2)
  console.log(jsonString)
}

to read via html, try this script (define an element which id is "json")

var id = '#######';
var gid = '######';
var url = 'https://docs.google.com/spreadsheets/d/'+id+'/gviz/tq?tqx=out:json&tq&gid='+gid;
fetch(url)
  .then(response => response.text())
  .then(data => document.getElementById("json").innerHTML=myItems(data.slice(47, -2))  
  );
function myItems(jsonString){
  var json = JSON.parse(jsonString);
  var table = '<table><tr>'
  json.table.cols.forEach(colonne => table += '<th>' + colonne.label + '</th>')
  table += '</tr>'
  json.table.rows.forEach(ligne => {
    table += '<tr>'
    ligne.c.forEach(cellule => {
        try{var valeur = cellule.f ? cellule.f : cellule.v}
        catch(e){var valeur = ''}
        table += '<td>' + valeur + '</td>'
      }
    )
    table += '</tr>'
    }
  )
  table += '</table>'
  return table
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!