/google-sheets-to-json

Convert Google Sheets into REST API (JSON Response)

Primary LanguageJava

Google Spreadsheet to REST API

Prerequisite

  • JDK 8+

Run

$ ./mvnw spring-boot:run

Usage

Step 1. You must publish your spreadsheet to the web, using File -> Publish To Web in your Google Spreadsheet.

Step 2. Copy <spreadsheetId> from spreadsheet URL. https://docs.google.com/spreadsheets/d/<spreadsheetId>/edit#gid=0

Step 3. Access readable REST API using the /api endpoint.

http://localhost:8080/api?id=<spreadsheetId>&sheet=<sheetNumber>

Parameters

  • spreadsheetId(required): The ID of your document. This is the big long aplha-numeric code in the middle of your document URL.
  • sheetNumber(optional): The number of the individual sheet you want to get data from. Your first sheet is 1, your second sheet is 2, etc. If no sheet is entered then 1 is the default.

Example

Request

http://localhost:8080/api?id=1sGMmQgWOhc_i_Gp1OJ9OVB41iN5rV4o8d-6YPCb4z7I

Response

{
  "columns": {
    "country": [
      "South Korea",
      "China",
      "Japan"
    ],
    "city": [
      "Seoul",
      "Beijing",
      "Tokyo"
    ]
  },
  "rows": [
    {
      "country": "South Korea",
      "city": "Seoul"
    },
    {
      "country": "China",
      "city": "Beijing"
    },
    {
      "country": "Japan",
      "city": "Tokyo"
    }
  ]
}