Open mherbold opened 6 years ago
Sorry - reopening because I double checked and this is an issue.
My sheet is at - https://docs.google.com/spreadsheets/d/1S2Cp8aSRFRLIbnSklmsUekCScKFfKRGft3aWHWfgFPw/edit#gid=726778124
Turn on "Collapse single row sheets". Export / visualize and take a look at the m_shipGameData structure. It is still an array instead of an object. Boo.
Hmm. Just tried it with only "Collapse single row sheets" enabled and got the following:
"m_shipGameData": {
"m_baseShipMass": 50,
"m_cargoPodBuyPrice": 500,
"m_cargoPodSellPrice": 500,
"m_cargoPodMass": 10
}
Do you have any other options enabled?
I also have "replace existing file" and "export sheet arrays" turned on, in addition to the "Collapse single row sheets". Everything else is left at the default setting.
Ah, it's the "Export sheet arrays" option that doing it. It forces all sheets to be arrays with its rows for elements. The way to get around this is to preface sheets that you want exported as arrays with "JA_" (for example: JA_m_shipGameData) and enable the "Array prefix" option in the advanced section. Then disable the "Export sheet arrays" option.
It's a little clunky admittedly, but I couldn't assume that a sheet with only one row was desired to be exported as an object instead of an array if both those options are enabled.
Ok - about a year ago the "collapse single row" was called the "unwrap single row" feature, and this worked perfectly for me (alongside with "export sheet arrays", multi-row sheets got turned into an array, single row sheets got turned into an object). So, now it's not possible to achieve what was previously possible with an older version of this extension? If you'll notice - it seems the "collapse single row" does nothing when "export sheet arrays" is turned on. Why not make this toggle useful?
Will the array prefix get removed from the actual object name that is written to the JSON?
Answered my own question - the prefix does not get saved to the JSON - good... but my sheets are now uglified with JA_ prefix on every tab except one. Any chance of making "collapse single row sheets" collapse sheets to an object when "export sheet arrays" is turned on? (otherwise, this toggle switch appears to do nothing)
Sorry for the inconvenience. About a year ago I completely redid the back end for JSON so it is much easier to work with and will produce expected results. The old method had some edge cases that produced functioning JSON with some invalid formatting but the new system should always be accurate to the JSON standard.
The problem with unwrapping all single row sheets is that there could be situations where a sheet is supposed to be an array, but it only contains one element (meaning only one row). I couldn't assume that sheet should be collapsed instead of being exported as an array, so the new workflow had to be introduced. It's not as convenient, granted, but it is more flexible which is what I am going for.
What do you mean when you say "it seems the the "collapse single row" does nothing when "collapse single rows" is turned on."?
Also the prefix does not get exported.
With my spreadsheet when I have "export sheet arrays" turned on, toggling the "collapse single row sheets" on and off both produce identical JSON files. So "collapse single row sheets" seems to do nothing when "export sheet arrays" is turned on.
Ah. Yeah, some options stomp on others. For example: "Unwrap single row sheets" will override "Collapse single row sheets". I thought I had made it so you could use the "CS" prefix and enable "Collapse sheet prefix" to force a sheet to be collapsed instead of exporting as an array, but I just tested it and apparently not. Adding that should do the same thing as the "JA" method I described above, just with far less sheet names requiring changes.
I'm not using the unwrap option so no stomping should be occurring.
I just took a quick look at your code and verified that when sheetArray is turned on, collapseSheet is completely ignored and will do nothing. Why not make it do something - I think this can easily be done by doing something like this on line 1105:
if ( collapseSheet ) { sheetArray = false; }
This was from a quick look thru - I haven't considered the nested stuff, etc (options I don't use). I might just clone your repo and experiment.
The "Collapse single row sheets" option does not work. This was previously called the "Unwrap single row sheets" feature. What it is supposed to do is take the single row and make it an object instead of an array. This no longer works. My single row sheet still gets turned into an array, even when this option is turned on. Please fix. :-\