Writing a recursive function to construct tree from nested array of objects

I’m new to Javascript and trying to construct a tree view from a backend response which is a list of AWS S3 objects, my problem is the response needs to be constructed in parent>childeren>children form, so in the frontend can be easily displayed, I want to display a tree like below (mocked tree structure):
https://stackblitz.com/edit/angular-girq88
and below is the service response which I want to construct tree view from:
https://jsoneditoronline.org/?id=8b85a9e5f8054df582191f391dc43193
My goal is to build a recursive function that loops in the response and constructs a tree (deep level) that can be like below:

  • folder1/
    project1/
    samplev1.psd
    samplev2.psd
  • folder2/
    project2/
    sampleV2.psd
    can you guys help me with this, thank you :slight_smile: