Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Docs Spreadsheet to JSON

I've seen numerous articles on this but they seem outdated, for instance none of the Google Docs Spreadsheet urls has key parameter. I read this as well: JSON data from google spreadsheet

Then I read this to access data https://developers.google.com/gdata/samples/spreadsheet_sample

My spreadsheet exists at: https://docs.google.com/spreadsheets/d/1SKI5773_68HiSve1fsz7fr4gotjFWHB7KBuVsOlLz6I/edit#gid=0

I've tried using this code, I think I have a problem with the key or syntax, please guide to fix.

<script src="http://spreadsheets.google.com/feeds/feed/1SKI5773_68HiSve1fsz7fr4gotjFWHB7KBuVsOlLz6I/worksheet/public/basic?alt=json-in-script&callback=importGSS"></script>

<script type="text/javascript">

    function importGSS(json) {
        console.log('finished');
    }
</script>
like image 787
user2727195 Avatar asked May 13 '14 21:05

user2727195


People also ask

Does Google Sheets support JSON?

Yes, Google Sheets can import JSON files, you can do it with Google Apps Script or third-party no-code apps like Zapier.

Can you convert Excel into JSON?

There is no predefined method in Excel to convert the Excel data to JSON. You can either use online Excel to JSON conversion software or download an add-in from the Microsoft store for this task to get done.

Can Google Sheets export to XML?

Export Sheet Data - Google Workspace Marketplace. Open source add-on for Google Sheets that allows users to export sheets as XML or JSON.

How do I convert a Google spreadsheet to JSON?

Start a new spreadsheet like you normally do in Google Sheets Head over to sheets.google.com and start a new Google Sheet. While in your new spreadsheet you’ll need to do two quick things that will make your spreadsheet PUBLIC. I know this sounds scary but to be able to convert your spreadsheet’s data to JSON it needs to publicly available.

How to use Google Sheets as a JSON API?

Google Sheet as a JSON API 1 Prepare your Spreadsheet For the Spreadsheet you're going to connect to sheet2api, the first row (1) must only contain column names. ... 2 Create Spreadsheet API As per the video below: Share & Copy the link to your Google Sheet. Create a Spreadsheet API using that link. ... 3 Try out your new JSON API

What can I do with Google Spreadsheets?

With this guide, you'll be able to: Create a spreadsheet in Google Spreadsheets. Publish the spreadsheet to the web. Generate a JSON endpoint.

How do I create a public JSON endpoint in Google Spreadsheets?

Create a spreadsheet in Google Spreadsheets. Publish the spreadsheet to the web. Generate a JSON endpoint. Open the spreadsheet for public collaboration. Pass the JSON endpoint to your back-end developer.


2 Answers

The src attribute in your script tag is an invalid link (and you can see this for yourself by viewing your link directly in a browser).

The feed/key/worksheet section of the URL has the right key but the wrong feed and worksheet.

In the URL, replace "feed" with either "cells" (separate value for each cell) or "list" (separate value for each row).

At the same time, replace "worksheet" with "od6" (indicating the leftmost, or default, sheet - see this blog post for accessing other sheets).

If you view this new URL directly in a browser, you can see that it returns a meaningful value.

Your final script tag might look like this:

<script src="https://spreadsheets.google.com/feeds/list/1SKI5773_68HiSve1fsz7fr4gotjFWHB7KBuVsOlLz6I/od6/public/values?alt=json-in-script&callback=importGSS"></script>

For more info, you can see an example on the Google Developers site

like image 79
sfletche Avatar answered Oct 07 '22 19:10

sfletche


APISpark PaaS has a feature to create and deploy a custom JSON API based on a GSpreadsheet. That might help and give you more control on the web API (CORS support, authentication, custom domain and so on).

See the tutorial here: https://apispark.com/docs/tutorials/google-spreadsheet

like image 20
Jerome Louvel Avatar answered Oct 07 '22 21:10

Jerome Louvel