In a bit of a pickle here, and I'm hoping someone can help. I've got some JSON data that is returned as part of a web API call that has the following format:
Code:
[{path: 'f1/f2/', id:1, name: 'somename'}, {path: 'f1/f2/', id: 2, name: 'anotherName'}, {path:'f1/f3/', id: 3, name: 'yak'}, {path: 'f3/f4/', id:4, name: 'foo'},
{path: 'f5/', id: 5, name: 'bar'}]
It's a stripped down version... but you get the idea... the key here is path... it can repeat, it can be one level, it could be two it could be 5 it could be more, it could be less.
I need to be able to take that and transform that into another JSON format, that looks like this:

Code:
[{
  value: 'f1',
  nodes: [
    {value: 'f2',
      nodes: [
       {value: 'somename', id: 1, ... (more properties) },
       {value: 'anotherName', id: 2, ... (more properties) }, ...
     ]
    },
    {value: 'f3',
      nodes: [
       {value: 'yak', id: 3, ... (more properties) }, ...
       ]
    }, ...]
  }
....
and so on
Basically I need to break down the path property to that it will form a tree, then put each item into that path. Fortunately everything will already be sorted, so once I go down a particular pathway, I'm done with it, I won't need to retrace it later.

I'm doing this in a React-Redux reducer, so the language is JS... and I'm just having trouble wrapping my head around how to build it out. there are more properties than the ones I listed too, but those are the important ones. If I can get those mapped out, I think I can figure out how pull the others along for the ride..


-tg