I need to convert a csv file into a hierarchical JSON object (preferably using Python). I thought that the script I have (below) does a correct job of converting to JSON, bu
Order of elements is not important for json.
The json you are producing is wrong, though. The example you gave that you are trying to match does not have a "subject" key at the top level. It shows just "name" => "flare", and a list of children. Your script is producing json with a "subject" key.
Instead of
subject_dict = {'name':subject,'type':'subject','children':branch_list}
try
subject_dict = {'name':subject,'children':branch_list}
I don't know about D3.js, so I can't say if it expects an object that follows one exact structure.
Tip: one good tool to check the structure of json objects is http://jsoneditor.appspot.com. Just paste your string in there and click on "Go to Treeview". It will hellp you find differences between what you have and what you want very easily.