Restructuring Object Hierarchy [closed]

Hello I’m trying to convert an initial object that i’m starting out with to the expected structured format. Any help is welcome, I know this will involve creating a recursive function. However, I’m a bit puzzled as to how to set it all up. Thank you in advance.

Initial

const x = {
 Id: { name: 'Id', fieldsByTypeName: {} },
 Subject: { name: 'Subject', fieldsByTypeName: {} },
 Profile: {
  Id: { name: 'Id', fieldsByTypeName: {} },
  Name: { name: 'Name', fieldsByTypeName: {} },
  CreatedBy: {
    name: 'CreatedBy',
    fieldsByTypeName: {
       CreatedBy: {
       Id: { name: 'Id', fieldsByTypeName: {} },
       Name: { name: 'Name', fieldsByTypeName: {} },
     }
    }
  },
  Record: {
     name: 'Record', 
     fieldsByTypeName: {
      Record: {
         Id: { name: 'Id', fieldsByTypeName: {} },
         Name: { name: 'name', fieldsByTypeName: {} },
      }
    }
  }
 }
}

Expected:

{
 Id: true,
 Subject: true,
 Profile: {
   Id: true,
   Name: true,
   CreatedBy: { 
      Id: true,
      Name: true
   },
   Record: {
    Id: true,
    Name: true
   }
 }
}