title: Python : How to convert data from excel in table form into json
body: <p><a href="https://i.stack.imgur.com/4No1k.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4No1k.jpg" alt="enter image description here" /></a></p>
  <p><a href="https://docs.google.com/spreadsheets/d/15Lbl8N4ZDWQZeAexVIL_SnLGYUqnfC4G" rel="nofollow noreferrer">Here</a> is the table created in excel  and is to be converted into json data. Like this :</p>
  <pre><code>    { &quot;maintitle&quot;: {&quot;idno&quot;: &quot;10&quot;,
             &quot;subheading&quot;: [ {  &quot;prop&quot;: &quot;val1&quot;,
                               &quot;prop2&quot;: &quot;val12&quot;,
                              &quot;attrib&quot;: {&quot;type&quot;: &quot;well&quot;},
                               &quot;attri&quot;: {&quot;pos&quot;: &quot;[]&quot;}},
                             {  &quot;type&quot;: &quot;ok&quot;,
                              &quot;prop11&quot;: {&quot;subprop1&quot;: &quot;10&quot;,
                                         &quot;subprop2&quot;: &quot;abc&quot;,
                                         &quot;subprop3&quot;: &quot;0.202&quot;,
                                         &quot;subprop4&quot;: &quot;moreval1&quot;},
                            &quot;moreprop&quot;: {  &quot;type&quot;: &quot;dot&quot;,
                                       &quot;diffdata&quot;: [&quot;3030.22&quot;,&quot;3903.22&quot;]}
                               }
                             ]
                  }
    }
  </code></pre>
  <p>Here : Column names ending with [x] are read as python list having elements below it present at index x.
  Column names without [x] are read as python dictionary.</p>
  <p>Below is the code but it does not give the desired result:</p>
  <pre><code>from mergedeep import merge, Strategy
  # data from excel is read &amp; saved in variable columnlist
  columnlist=[['maintitle', 'idno'],
   ['maintitle', 'subheading[0]', 'prop'],
   ['maintitle', 'subheading[0]', 'prop2'],
   ['maintitle', 'subheading[0]', 'attrib', 'type'],
   ['maintitle', 'subheading[0]', 'attri', 'pos'],
   ['maintitle', 'subheading[1]', 'type'],
   ['maintitle', 'subheading[1]', 'prop11', 'subprop1'],
   ['maintitle', 'subheading[1]', 'prop11', 'subprop2'],
   ['maintitle', 'subheading[1]', 'prop11', 'subprop3'],
   ['maintitle', 'subheading[1]', 'prop11', 'subprop4'],
   ['maintitle', 'subheading[1]', 'moreprop', 'type'],
   ['maintitle', 'subheading[1]', 'moreprop', 'diffdata[0]'],
   ['maintitle', 'subheading[1]', 'moreprop', 'diffdata[1]']]
  
  jsondict={}
  for col in columnlist:
      tmpdict=''
      for key in reversed(col):
          if '[' in key:
              tmpdict = {key: [tmpdict]} 
          else:
              tmpdict = {key: tmpdict}
      merge(jsondict,tmpdict, strategy=Strategy.ADDITIVE)
  
  print(jsondict)
  </code></pre>
  <p>I think this can be achieved with recursion. How can it be done using python ?</p>