Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a solution for Dictionaries with nested objects #157

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Garfield1002
Copy link

A proposed solution for using dictionaries with nested objects

Corresponding issue: #151

Implemented solution

A new header type surrounded with [{}]. This will create a new object names after the cell content rather than the column title.

Usage

We can now address the issue raised in 151 with this new header

[{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

Outcome (All examples are done with only the Nested Elements options enabled):

{
  "Sheet1": {
    "Class A": {
      "PSIPL": 9,
      "SMCSLU": 2
    },
    "Class B": {
      "PSIPL": 6,
      "SMCSLU": 4
    },
    "Class C": {
      "PSIPL": 4,
      "SMCSLU": 6
    },
    "Class D": {
      "PSIPL": 3,
      "SMCSLU": 8
    },
    "Class E": {
      "PSIPL": 1,
      "SMCSLU": 10
    }
  }
}

Advantages

We can take this a step further and are able to rework the advanced country example to now include different objects as well as lists

[{Continents}] [{Continents}][{Countries}] [{Continents}][{Countries}][Cities]{#Name} [{Continents}][{Countries}][Cities]Population
North America Canada Toronto 2615000
North America Canada Vancouver 603500
North America Canada Montreal 1650000
North America United States New York 8273000
North America United States Chicago 2697000
North America United States Los Angeles 3849000

Output

{
  "Sheet1": {
    "North America": {
      "Canada": {
        "Cities": [
          {
            "Name": "Toronto",
            "Population": 2615000
          },
          {
            "Name": "Vancouver",
            "Population": 603500
          },
          {
            "Name": "Montreal",
            "Population": 1650000
          }
        ]
      },
      "United States": {
        "Cities": [
          {
            "Name": "New York",
            "Population": 8273000
          },
          {
            "Name": "Chicago",
            "Population": 2697000
          },
          {
            "Name": "Los Angeles",
            "Population": 3849000
          }
        ]
      }
    }
  }
}

Code changes

  • Added Dict to SubpathTypes and changed getSubpathTypeJson to accomodate this new header
  • Changed getKeyPath and trimKeySubpath to accomodate for the 2 character identifier
  • Changed exportSpreadsheetJson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enabling Nested Elements causes non-nested element sheet to be exported incorrectly
1 participant