bassarisse / google-spreadsheet-to-json

Simple tool to export Google Spreadsheets to JSON files, though Node API or CLI
The Unlicense
134 stars 33 forks source link

Hash Worksheet titles #14

Open cfoulston opened 7 years ago

cfoulston commented 7 years ago

Would be nice if we could include worksheet titles in the json result. Currently if all worksheets are included in a single json. Each worksheet is an array element. Maybe a flag to determine if worksheets are treated as objects or array elements?

bassarisse commented 7 years ago

I think this is the same problem this PR is addressing, right? As mentioned there, we should probably add an option for that.

cfoulston commented 7 years ago

Similar. I'd like the Worksheet Title to become the name of the object like:

{
    "Worksheet Title 0": {

        "Hashed Id 0": {
            "Column 2": "Some Value",
            "Column 3": "Some Value"
        },      
        "Hashed Id 1": {
            "Column 2": "Some Value",
            "Column 3": "Some Value"
        }
    },
    "Worksheet Title 1": {

        "Hashed Id 0": {
            "Column 2": "Some Value",
            "Column 3": "Some Value"
        },      
        "Hashed Id 1": {
            "Column 2": "Some Value",
            "Column 3": "Some Value"
        }
    },
    "Worksheet Title 3": {

        "Hashed Id 0": {
            "Column 2": "Some Value",
            "Column 3": "Some Value"
        },      
        "Hashed Id 1": {
            "Column 2": "Some Value",
            "Column 3": "Some Value"
        }
    }
}

I'm trying to integrate GSheets data into Google Firebase. The JSON Editor is horrible over there so I was hoping to use this and use their "Import JSON" feature. However, the Firebase structure is a tree and not array. So I need to be able to use strings as the name of an object.

In that PR, seems like the solution is to add a "title" and "index" as values. My request is different in that I want that "title" to be the key/hash of the Worksheet object

bassarisse commented 7 years ago

If this wasn't a CLI tool, I think the suggested format (a list of objects with title and index) would be better, as it is more generic and can be transformed into whatever format the user wants. Like so:

data.reduce((result, sheet) => {
  result[sheet.title] = sheet.data
  return result
}, {})

However, as I'd like the tool to remain as standalone as possible, offering a way to control the result is more adequate, so I'll probably add a option so you can choose between various result formats (one of them being what you need).

cfoulston commented 7 years ago

That would be great. Thanks