title: Create nested JSON from flat csv
body: <p>Trying to create a 4 deep nested JSON from a csv based upon this example:</p>
  
  <pre><code>Region,Company,Department,Expense,Cost
  Gondwanaland,Bobs Bits,Operations,nuts,332
  Gondwanaland,Bobs Bits,Operations,bolts,254
  Gondwanaland,Maureens Melons,Operations,nuts,123
  </code></pre>
  
  <p>At each level I would like to sum the costs and include it in the outputted JSON at the relevant level. </p>
  
  <p>The structure of the outputted JSON should look something like this:</p>
  
  <pre><code>    {
            "id": "aUniqueIdentifier", 
            "name": "usually a nodes name", 
            "data": [
                  {
                        "key": "some key", 
                        "value": "some value"
                  }, 
                  {
                        "key": "some other key", 
                        "value": "some other value"
                  }
            ], 
            "children": [/* other nodes or empty */ ]
      }
  </code></pre>
  
  <p>(REF: <a href="http://blog.thejit.org/2008/04/27/feeding-json-tree-structures-to-the-jit/" rel="nofollow">http://blog.thejit.org/2008/04/27/feeding-json-tree-structures-to-the-jit/</a>)</p>
  
  <p>Thinking along the lines of a recursive function in python but have not had much success with this approach so far... any suggestions for a quick and easy solution greatly appreciated?</p>
  
  <p>UPDATE:
  Gradually giving up on the idea of the summarised costs because I just can't figure it out :(. I'not much of a python coder yet)! Simply being able to generate the formatted JSON would be good enough and I can plug in the numbers later if I have to.</p>
  
  <p>Have been reading, googling and reading for a solution and on the way have learnt a lot but still no success in creating my nested JSON files from the above CSV strucutre. Must be a simple solution somewhere on the web? Maybe somebody else has had more luck with their search terms????</p>