I need some assistance on a somewhat simple issue.

I'm trying to convert the content of a json file from this:

```
    {   "Timestamp": "Timestamp",
        "name": "SVCHOST.EXE",
        "icon": "binary_icon.png",
        "Process": SVCHOST.EXE,
        "Pid": "876",
        "PPID": "500"],
        "children": [Process details])
    },
    {   "Timestamp":"Timestamp",
        "name": "LSAS.EXE",
        "icon": "binary_icon.png",
        "Process": "LSAS.EXE",
        "Pid": "500",
        "PPID": "4"],
        "children": [Process details])
    },
    {   "Timestamp":"Timestamp",
        "name": "SYSTEM",
        "icon": "binary_icon.png",
        "Process": "SYSTEM",
        "Pid": "4",
        "PPID": "0"],
        "children": [Process details])
    }

```

To this:

```
{
"name": "Root", 
"children": [
    {
        "name": "4", 
        "children": [
            {
                "name": "500", 
                "children": [
                    {
                        "name": "876", 
                        "children": []
                    }
                ]
            }
        ]
    }
}

```

To create a node tree graph in the end.

But after a lot of trial and error, and still not close to the output I need. I'm asking for some pointer, tips or tricks.
Any help is much appreciated.

Thanks,

Here is my most recent attempt.

```
import json

links = ({
"Timestamp": "Timestamp",
    "name": "SVCHOST.EXE",
    "icon": "binary_icon.png",
    "Process": "SVCHOST.EXE",
    "Pid": "876",
    "PPID": "500",
    "children": "Process_details"
},
  {
    "Timestamp":"Timestamp",
    "name": "LSAS.EXE",
    "icon": "binary_icon.png",
    "Process": "LSAS.EXE",
    "Pid": "500",
    "PPID": "4",
    "children": "Process_details"
},
  {
    "Timestamp":"Timestamp",
    "name": "SYSTEM",
    "icon": "binary_icon.png",
    "Process": "SYSTEM",
    "Pid": "4",
    "PPID": "0",
    "children": "Process_details"
})

parent_proc_node = {}
root = {'name': 'Root', 'children': []}
for item in procs:
    parent_node = parent_proc_node.get(item['Pid'])
    if not parent_node:
        parent_proc_node[item['Pid']] = parent_node = {'name': item['PPID']}
        root['children'].append(parent_node)
    parent_proc_node[item['PPID']] = child_node = {'name': item['Pid']}
    parent_node.setdefault('children', []).append(child_node)

print json.dumps(root, indent=4)

```

Current output:

```
{
"name": "Root", 
"children": [
    {
        "name": "500", 
        "children": [
            {
                "name": "876", 
                "children": [
                    {
                        "name": "500", 
                        "children": [
                            {
                                "name": "4"
                            }
                        ]
                    }
                ]
            }
        ]
    }
}

```

The output is now what I want, but im still not able to correctly match parent process with children.
What am I doing wrong?

The correct output would be like this:

```
{
"name": "Root", 
"children": [
    {
        "name": "4", 
        "children": [
            {
                "name": "500", 
                "children": [
                    {
                        "name": "876", 
                        "children": [
                            {
                                "name": ""
                            }
                        ]
                    }
                ]
            }
        ]
    }
}

```