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

Nesting? #138

Closed handes2355 closed 3 years ago

handes2355 commented 3 years ago

I'm trying to create this format:

{
    name: "Interaction",
    userSays: [
        "Hello",
        "Hi"
    ],
    responses: [
        {
            type: "text",
            elements: ["Hi, how are you", "Hello! What can I do for you?"]
        }
    ]
}

This is my sheet

https://docs.google.com/spreadsheets/d/1egdQFcCgXPa-iSvcQYzuDBqWXmDhYgmov5NiLDqMwm4/edit?usp=sharing

Synthoid commented 3 years ago

I think I have what you are looking for:

{
  "Sheet1": [
    {
      "name": "Interaction",
      "userSays": [
        "Hello",
        "Hi"
      ],
      "responses": [
        {
          "type": "text",
          "elements": [
            "Hi",
            "how are you",
            "Hello! What can I do for you?"
          ]
        }
      ]
    },
    {
      "name": "Secon Interaction",
      "userSays": [
        "one",
        "two",
        "three"
      ],
      "responses": [
        {
          "type": "text",
          "elements": [
            "four",
            "five",
            "six"
          ]
        }
      ]
    }
  ]
}

I got that with the following sheet:

Sheet name: NA_Sheet1

name JA_userSays [responses]{#type} [responses]{#type}JA_elements
Interaction Hello, Hi text Hi, how are you, Hello! What can I do for you?
Secon Interaction one, two, three text four, five, six

With Nested Elements, Array Prefix, and Nested Array Prefix enabled.

handes2355 commented 3 years ago

Thanks for taking a look. I'm getting this error message

TypeError: Cannot set property 'elements' of undefined at exportSpreadsheetJson (ExportSheetData:1802:58) at exportJson (ExportSheetData:889:5) at GS_INTERNAL_top_function_call.gs:1:8

https://docs.google.com/spreadsheets/d/1egdQFcCgXPa-iSvcQYzuDBqWXmDhYgmov5NiLDqMwm4/edit?usp=sharing

Synthoid commented 3 years ago

Looks like the keys are missing the #. Your key path should be:

[responses]{#type}

Not:

[responses]{type}

handes2355 commented 3 years ago

Thak you - that was it. Appreciate the assist