title: Convert a flat tab-delimited file into Json nested structure
body: <p>I need to convert a flat file in the following format into JSON format. The input and output is shown as under. I have come across this: <a href="https://stackoverflow.com/questions/17043229/create-nested-json-from-csv">Create nested JSON from CSV</a> post however, I have an extra information/field  <code>level</code> that is used to determine the nested structure in the JSON output.  Python <code>pandas</code> does have <code>df.to_json</code> but couldn't find a way to write in the desired output format. Any help will be appreciated.    </p>
  
  <p>Input: </p>
  
  <pre><code>name    level   children    size
  aaa 7   aaab    2952
  aaa 7   aaac    251
  aaa 7   aaad    222
  aaab    8   xxx 45
  aaab    8   xxy 29
  aaab    8   xxz 28
  aaab    8   xxa 4
  aaac    8   ddd 7
  aaac    8   xxt 4
  aaac    8   xxu 1
  aaac    8   xxv 1
  ddd 9   ppp 4
  ddd 9   qqq 2
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>{
   "name": "aaa",
   "size": 5000,
   "children":
      [
          {
          "name": "aaab",
          "size": 2952,
          "children": [
                    {"name": "xxx", "size": 45},
                    {"name": "xxy", "size": 29},
                    {"name": "xxz", "size": 28},
                    {"name": "xxa", "size": 4}
                    ]
          },
  
          {
          "name": "aaac",
          "size": 251,
          "children": [
                          {
                          "name": "ddd",
                          "size": 7,
                          "children": [
                                       {"name": "ppp", "size": 4},
                                       {"name": "qqq", "size": 2}
                                       ]
                          },
                          {"name": "xxt", "size": 4},
                          {"name": "xxu", "size": 1},
                          {"name": "xxv", "size": 1}
                       ]
          },
          {"name": "aaad","size": 222}
       ]
  }
  </code></pre>