npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ayyyub/sheet2json

v1.0.2

Published

Convert Google Sheets data to JSON

Downloads

140

Readme

sheet2json

sheet2json is a Node.js package that allows you to easily convert data from Google Sheets into JSON format. With this package, you can fetch spreadsheet data, where column headers are used as keys in the resulting JSON objects, making it simple to work with structured data from Google Sheets.

Features

  • Fetch data from multiple sheets within a single Google Spreadsheet.
  • Convert spreadsheet data into JSON format with column headers as keys.
  • Handle various data types, including strings, numbers, booleans, and null values.

Installation

To install sheet2json, you can use npm:

npm install @ayyyub/sheet2json

Usage

First, ensure you have a valid access token for the Google Sheets API. You can obtain this token by following the authentication steps in the Google Sheets API documentation.

Here is an example of how to use the sheet2json package:

const sheet2json = require("@ayyyub/sheet2json");

const sheet = new sheet2json(
  "YOUR_ACCESS_TOKEN_HERE"
);

async function main() {
  try {
    const data = await sheet.get("YOUR_SPREADSHEET_ID_HERE");
    console.log(data);
  } catch (error) {
    console.error("Error fetching data:", error);
  }
}

main();

Parameters

  • accessToken: Your Google API access token, which grants permission to access your Google Sheets data.

Method

  • get(spreadsheetId: string): Fetches spreadsheet data and converts it to JSON format.
    • spreadsheetId: The ID of the Google Spreadsheet you want to access.

Returns

The get method returns a promise that resolves to an object containing JSON data for each sheet in the specified spreadsheet. Each key corresponds to a sheet name, and its value is an array of objects representing rows in that sheet, with column headers as keys.

Example

Assuming you have a Google Spreadsheet with the following structure:

| Name | Age | Active | |-------|-----|--------| | Alice | 30 | true | | Bob | 25 | false |

Using the above code, the output would look like this:

{
  "Sheet1": [
    { "Name": "Alice", "Age": 30, "Active": true },
    { "Name": "Bob", "Age": 25, "Active": false }
  ]
}

Error Handling

If there is an error accessing the spreadsheet or if the data is invalid, an error will be thrown with a descriptive message. Make sure to handle these errors appropriately in your application.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please submit a pull request or open an issue to discuss improvements or new features.