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

Hash Worksheet titles

Open cfoulston opened this issue 7 years ago • 4 comments

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?

cfoulston avatar May 10 '17 02:05 cfoulston

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

bassarisse avatar May 11 '17 13:05 bassarisse

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

cfoulston avatar May 11 '17 17:05 cfoulston

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).

bassarisse avatar May 11 '17 18:05 bassarisse

That would be great. Thanks

cfoulston avatar May 11 '17 18:05 cfoulston