Sastry Kasibotla
Sastry Kasibotla

Reputation: 138

How to get google sheet multiple tabs data as JSON?

Can you some help to get google sheets multiple tabs data as single JSON ?

Upvotes: 0

Views: 879

Answers (1)

Rafa Guillermo
Rafa Guillermo

Reputation: 15357

Answer:

You can use the Sheets API to get the data of each sheet pre-compiled as a JSON.

More Information:

The spreadsheets.get endpoint of the Google Sheets API allows you to get the data from a Spreadsheet by specifying the Spreadsheet ID. The URL for the endpoint is:

https://sheets.googleapis.com/v4/spreadsheets/SPREADSHEET-ID

You can use a field mask to narrow down the data in the response you get from the API. In order to only get the Sheet name and the data, you can use:

sheets(properties/title,data/rowData/values/userEnteredValue)

to test using the Try this API, or if using the URL directly:

https://sheets.googleapis.com/v4/spreadsheets/yourSpreadsheetId?fields=sheets(properties/title,data/rowData/values/userEnteredValue)

Example Response:

{
  "sheets": [
    {
      "properties": {
        "title": "Sheet1"
      },
      "data": [
        {
          "rowData": [
            {
              "values": [
                {
                  "userEnteredValue": {
                    "numberValue": 1
                  }
                },
                {
                  "userEnteredValue": {
                    "numberValue": 12
                  }
                }
              ]
            },
            {
              "values": [
                {},
                {},
                {
                  "userEnteredValue": {
                    "numberValue": 123
                  }
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

References:

Upvotes: 2

Related Questions