node-google-spreadsheet icon indicating copy to clipboard operation
node-google-spreadsheet copied to clipboard

Add toJson functionality for SpreadsheetRow objects

Open davidholyko opened this issue 6 years ago • 2 comments

Functionality that would convert the instance of SpreadsheetRow to just it's data with the signature [columnname]: value would be super helpful

davidholyko avatar Oct 16 '19 15:10 davidholyko

Good idea :)

I've just a published a new version of this module which is a complete rewrite using Google's V4 Sheets API (v3 is being deprecated on March 3, 2020). Docs available here - https://theoephraim.github.io/node-google-spreadsheet

Feel free to open a PR, and if not, I'll try to get it into the next round of improvements.

Thanks! 😄

theoephraim avatar Feb 03 '20 18:02 theoephraim

Did this as a quick workaround with the latest node version or babel confign you can simplify it using Òbject.fromEntries instead of pushing every prop.

rows.toJson = rows.reduce((acc, row) => {
    const cleanRow = {}
    const rowEntries = Object.entries(row)
    rowEntries.forEach(([key, value]) => {
    if (key.charAt(0) !== "_") {
        cleanRow[key] = value
    }
    })
    acc.push(cleanRow)
    return acc
}, [])

lkappeler avatar Apr 03 '20 12:04 lkappeler

This is now implemented - https://theoephraim.github.io/node-google-spreadsheet/#/classes/google-spreadsheet-row?id=fn-toobject

theoephraim avatar Jun 26 '23 17:06 theoephraim