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

Combine multiple sheets into one single object? #110

Open magnusfox opened 4 years ago

magnusfox commented 4 years ago

Thank you for a great plug-in! What I'm requesting might be possible already, but I can not get it to work. I'm trying to configure an array of objects that contain sub-objects. This works fine using nested elements. However, I would like to be able to use multiple sheets to "write" into the same object. I.e, I want to define the basic properties of the object in one sheet and then use other sheets to define the "inner objects" of the objects defined in the first sheet. The below is an export from 2 different sheets using the unwrap feature. Is there any way that I could map the "InnerObject" so it would become a property of the regular object?

The reason for this is to avoid having one single enormous sheet with all the nested properties, but instead define the sub properties in other sheets.

{ "Objects": [ { "Id": "Object1", "RegularProperty": "Prop1" } ], "InnerObject": { "Title": "Inner object" } }

Any help much appreciated!

Synthoid commented 4 years ago

What you want should be possible, you would just need to use the path to the end object as part of the key for each column. Something like:

[Objects]{#ROW}Title

Would look for a root array called Objects then grab the element indexed at the current row, and assign the Title field.

magnusfox commented 4 years ago

Sorry, I can't get it to work. I have two sheets, one with the following content:

[Objects]{#Id} | [Objects]Title Id1 | Title1 Id2 | Title2

And a second one with this: [Objects]{#ROW}SheetTwoProperty Value1 Value2

With Nested Elements only checked I get this result:

{ "US_Sheet1": { "Objects": [ { "Id": "Id1", "Title": "Title1" }, { "Id": "Id2", "Title": "Title2" } ] }, "US_Sheet2": { "Objects": [ { "SheetTwoProperty": "Value1" }, { "SheetTwoProperty": "Value2" } ] } }

If I use unwrapping with sheet prefix I get this:

{ "Objects": [ { "SheetTwoProperty": "Value1" }, { "SheetTwoProperty": "Value2" } ] }

In the second attempt the property from sheet 2 was overwriting instead of adding,