Python dump dict to json file
Question: I have a dict like this:

    
    
    sample = {'ObjectInterpolator': 1629,  'PointInterpolator': 1675, 'RectangleInterpolator': 2042}
    

I can't figure out how to dump the dict to a `json` file as showed below:

    
    
    {      
        "name": "interpolator",
        "children": [
          {"name": "ObjectInterpolator", "size": 1629},
          {"name": "PointInterpolator", "size": 1675},
          {"name": "RectangleInterpolator", "size": 2042}
         ]
    }
    

Is there a pythonic way to do this?

You may guess that I want to generate a `d3` treemap.


Answer: 
    import json
    with open('result.json', 'w') as fp:
        json.dump(sample, fp)
    

This is an easier way to do it.

The second line of code determines the destination of your new json file. In
this case it is the file `result.json` which will be created and get filled in
the third line: Your dict `sample` gets written into the `result.json`!

