Synthoid / ExportSheetData

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

Dynamic & Nested Object keys #79

Open Mindgames opened 5 years ago

Mindgames commented 5 years ago

Having issue with Object prefix / keys.

As i have been going through all relevant issues i see this question coming up over and over. Therefor it would be awesome to clear this out for once.

In my case i want to accomplish something similar with a large amount of objects, for simplicity let's try to re-create this

{
   "users":{
      "alice":{
         "full_name":"Alice Turing",
         "nickname":"Alice The Machine",
         "meta":{
            "type":"Ninja",
            "level":4
         }
      },
      "bart":{
         "full_name":"Bart Nukes",
         "nickname":"Bart The Furious",
         "meta":{
            "type":"Warrior",
            "level":1
         }
      }
   }
}   

And also this one

{
      "alice":{
         "full_name":"Alice Turing",
         "nickname":"Alice The Machine",
         "meta":{
            "type":"Ninja",
            "level":4
         }
      },
      "bart":{
         "full_name":"Bart Nukes",
         "nickname":"Bart The Furious",
         "meta":{
            "type":"Warrior",
            "level":1
         }
      }
   }    

Created a Google editable Google sheet with the mockup data here

Please supply solution + extension settings.

Synthoid commented 5 years ago

Can you make the mockup sheet public? I don't currently have permission to view it.

Mindgames commented 5 years ago

@Synthoid Damn, it's correct now https://docs.google.com/spreadsheets/d/18tSHmnMRUX_2888ZAZQ7FzRLxSpvmqMe0x2dXlyUWnM/edit?usp=sharing

Mindgames commented 5 years ago

@Synthoid Had any chance to check it yet?

karolwieczorek commented 5 years ago

You can try:

NOEX_users full_name nickname NOEX_{meta}type NOEX_{meta}level meta
alice Alice Turning Alice The Machine Ninja 1 =TEXTJOIN(""; TRUE; "{""type"": """; D2; """, ""level"": "; E2;"}")
bart Bar Nukes Bart The Furious Warrior 1 =TEXTJOIN(""; TRUE; "{""type"": """; D3; """, ""level"": "; E3;"}")
chuck Chuck Destroyer Chuck The Death Medic 2 =TEXTJOIN(""; TRUE; "{""type"": """; D4; """, ""level"": "; E4;"}")

sheet name: users

Settings: First version: Format: Select Sheet(s) All sheets Second version: Format: Select Sheet(s) Current sheet only

Both versions: Advanced: Ignore prefix: true - "NOEX_" JSON: Export cell arrays: true Advanced JSON: Export cell objects: true

I've used Export cell objects instead of Nested Elements since was not able to do exacly this example with Nested Elements.

You should get:

{
  "users": {
    "alice": {
      "full_name": "Alice Turning",
      "nickname": "Alice The Machine",
      "meta": {
        "type": "Ninja",
        "level": 1
      }
    },
    "bart": {
      "full_name": "Bar Nukes",
      "nickname": "Bart The Furious",
      "meta": {
        "type": "Warrior",
        "level": 1
      }
    },
    "chuck": {
      "full_name": "Chuck Destroyer",
      "nickname": "Chuck The Death",
      "meta": {
        "type": "Medic",
        "level": 2
      }
    }
  }
}