Synthoid / ExportSheetData

Add-on for Google Sheets that allows sheets to be exported as JSON or XML.
MIT License
234 stars 46 forks source link

Enabling Nested Elements causes non-nested element sheet to be exported incorrectly #151

Open colinamuzo opened 2 years ago

colinamuzo commented 2 years ago

This is my sheet: image This is how it is correctly exported WITHOUT nested elements enabled: { "ClassA": { "Class": "ClassA", "PSIPL": 9, "SMCLLU": 2 }, "ClassB": { "Class": "ClassB", "PSIPL": 6, "SMCLLU": 4 }, "ClassC": { "Class": "ClassC", "PSIPL": 4, "SMCLLU": 6 }, "ClassD": { "Class": "ClassD", "PSIPL": 3, "SMCLLU": 8 }, "ClassE": { "Class": "ClassE", "PSIPL": 1, "SMCLLU": 10 } } This is how it is INCORRECTLY exported WITH nested elements enabled: { "Class": "ClassE", "PSIPL": 1, "SMCLLU": 10 } The sheet does not have the NA_ prefix so i dont know why its affected at all by the setting. I want to be able to use nested element syntax on other sheets. Thanks for the free exporter btw :)

Synthoid commented 2 years ago

What export options do you have enabled? If the nested elements option is enabled, all sheets will use nested elements. The NA_ prefix is just a shortcut to help auto format sheet rows for nested elements, not the thing that actually enables nested elements.

colinamuzo commented 2 years ago

Hi Chris By "nested elements enabled" i mean the nested elements option is enabled.

If the nested elements option is enabled, all sheets will use nested elements.

Ok I didnt realise this. I thought that only the NA_ prefixed sheets would use nested elements.

The NA_ prefix is just a shortcut to help auto format sheet rows for nested elements

I don't really understand this. Can you explain what difference the NA_ prefix makes when the nested elements option is enabled?

Edit: Oh is it so you don't have to use the {SHEET}{ROW} stuff?

Synthoid commented 2 years ago

Correct, if a sheet name is prefaced with the NA_ prefix, every key will have {#SHEET}{#ROW} appended to it. This is basically a convenience option to streamline keys.

Currently, nested elements is an all or nothing option. Either every sheet uses them, or no sheet does. Probably it would be good to have a prefix to force nested elements on certain sheets.

colinamuzo commented 2 years ago

Probably it would be good to have a prefix to force nested elements on certain sheets.

Yes I think that is what I need. What is the chance of that feature being implemented and if so, what would the timescale be?

Just to be clear though....currently, if the nested elements option is enabled, then there is no way to preserve the correct JSON output structure I specified in my original post. Is that correct?

Synthoid commented 2 years ago

Probably that feature would be added when I start work on nested elements 2.0. Currently I'm tinkering with XML export optimizations, then I'll be looking into automation support (which may involve a total UI overhaul to support Google's new Card system). After that, there are a few minor quality of life improvements I'd like to make. Probably I won't be able to get to nested elements updates for a while unfortunately. Sorry for the wait!

I think it may be possible to get your current output, but it would require some creative key usage. Not sure off the top of my head what those keys should look like though. I can look into that when I get off work later tonight.

colinamuzo commented 2 years ago

I think it may be possible to get your current output, but it would require some creative key usage. Not sure off the top of my head what those keys should look like though. I can look into that when I get off work later tonight.

If you could get me that key syntax that would be amazing thanks! And thanks again for doing all this on your own time and for free.

If it turns out there is no way to preserve the JSON structure i want when the nested elements option is enabled....would it be feasible for me to clone/fork the repo and implement a temporary "fix" myself. I guess I would make it how I thought it was in the first place....that is that sheets without the NA_ prefix do not use nested element key syntax. I'm a quite experienced programmer so I think i could make the necessary code change; but I don't know how I'd go about using the modified extension in my sheet. Would I have to publish it?

Synthoid commented 2 years ago

Thinking about the feature more, I could probably work a NE_ prefix option in a release before getting to nested elements 2.0. That would still be a little ways out though.

As for forking the code, by all means feel free to do so! Part of why I want to keep ESD open source is to allow developers to make quick fixes and adjustments for their workflows. You can find documentation on setting up custom apps scripts here. It's a little tedious to get scripts working across multiple sheet files without publishing, but if you are only doing this in one sheet it should be a simple enough thing to implement on your end.

Sorry for how slow updates have been recently. I'd like to put out one release a month, but it's been harder and harder to put time together to work on ESD recently. Definitely one of the downsides to working on open source software while juggling work to feed my crippling addiction to food and shelter.

colinamuzo commented 2 years ago

Dude don't apologize. You've been super helpful with this issue. I'm in awe of anyone who gets an OSS project out into the wild and used by people. You're doing a great job 👍

Synthoid commented 2 years ago

Thanks, I appreciate the encouragement! My schedule should be clearing up soon so hopefully I can get some updates out!

Garfield1002 commented 1 year ago

I submitted a PR with a potential fix to this issue. It does not use a NE_ header, but instead adds a new option to wrap column titles with [{}].

With this change, you can solve you issue with this new table:

[{Class}] [{Class}]PSIPL [{Class}]SMCSLU
Class A 9 2
Class B 6 4
Class C 4 6
Class D 3 8
Class E 1 10