title: converting a complex array into json in javascript
body: <p>Basically I want to convert an Excel Data into a complex JSON. So far, I've converted the excel data into array of rows like below. First array will always be the headings of the table.</p>
  
  <pre><code>const row = [["rule", "key_phrase", "doc_type", "doc_priority", "section_title"],
  ["approval related", "approved", "assessment report", 1, "4. Recommendations, outcome"],
  ["prime designation", "prime,prime designation", "assessment-report", 1, "1. Background information on the procedure, 1.1. Submission of the dossier"],
  ["single-arm trials", "single-arm, single arm, single, arm", "NDA", 2, "5.1 Pharmaco dymnamic properties, Clinical Efficacy"],
  ["single-arm trials", "single-arm, single arm, single, arm", "NDA", 2, "CLINICAL/STATISTICAL/PHARMACOVIGILANCE, Clinical Program"]]
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/PrHUR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PrHUR.png" alt="enter image description here"></a></p>
  
  <p>And now I want to convert that array into a JSON. Every comma <code>,</code> separated values should go into the same key. <strong>For eg. key_phrase: ["prime", "prime designation"]</strong>.</p>
  
  <p>So from the above excel data, the first JSON object should be something like this: </p>
  
  <pre><code>{
    "biz_rules": [
      {
        "rule": "approval related",
        "key_phrase": [
          "approved"
        ],
        "doc": [
          {
            "type": "assessment-report",
            "priority": 1,
            "sections": [
              {
                "title_keywords": [
                  "4. Recommendations",
                  "outcome"
                ],
                "content_keywords": [
                  "marketing authorization"
                ]
              }
            ]
          }
        ]
      },
      {
        "rule": "prime designation",
        "key_phrase": [
          "prime",
          "prime designation"
        ],
        "doc": [
          {
            "type": "assessment-report",
            "priority": 1,
            "sections": [
              {
                "title_keywords": [
                  "1. Background information on the procedure",
                  "1.1. Submission of the dossier"
                ],
                "content_keywords": [
                  "prime"
                ]
              }
            ]
          }
        ]
      },
      {
        "rule": "single-arm trials",
        "key_phrase": [
          "single-arm",
          "single arm",
          "single",
          "arm"
        ],
        "doc": [
          {
            "type": "NDA",
            "priority": 2,
            "sections": [
              {
                "title_keywords": [
                  "5.1 Pharmacodynamic properties",
                  "Clinical efficacy"
                ],
                "content_keywords": [
                  "single-arm trials"
                ]
              },
              {
                "title_keywords": [
                  "CLINICAL/STATISTICAL/PHARMACOVIGILANCE",
                  "Clinical Program"
                ],
                "content_keywords": [
                  "single-arm trials"
                ]
              }
            ]
          },
          {
            "type": "assessment-report",
            "priority": 1,
            "sections": [
              {
                "title_keywords": [
                  "5. Clinical efficacy ",
                  "2.5.2. Main studies"
                ],
                "content_keywords": [
                  "single-arm trials"
                ]
              }
            ]
          },
          {
            "type": "Clinical trials",
            "priority": 2,
            "sections": [
              {
                "content_keywords": [
                  "single-arm trials"
                ]
              }
            ]
          },
          {
            "type": "press-release",
            "priority": 2,
            "sections": [
              {
                "content_keywords": [
                  "single-arm trials"
                ]
              }
            ]
          },
          {
            "type": "press-releases",
            "priority": 2,
            "sections": [
              {
                "content_keywords": [
                  "single-arm trials"
                ]
              }
            ]
          },
          {
            "type": "media-releasess",
            "priority": 2,
            "sections": [
              {
                "content_keywords": [
                  "single-arm trials"
                ]
              }
            ]
          }
        ]
      }
  ]}
  </code></pre>
  
  <p>Ignoring <strong>content_keywords</strong>. The rules are uniquely divided as per sections. So every <strong>title_keywords</strong> inside the sections would be separate rule in excel. </p>
  
  <p>Any help would be much appreciated. Thanks in Advance. </p>