Transform flat json to nested json using javascript

I am trying to transform flat json to nested json using javascript with some sort of relationship. Please see below for the sample json data i am working with:


[{"id":1,"lob":"IT","product":"mobile","title":"64-bit app"}, 
{"id":2,"lob":"SCI","product":"book","title":"a book"},
{"id":3,"lob":"IT","product":"laptop","title":"this is laptop"},  
{"id":4,"lob":"IT","product":"laptop","title":"another laptop"},
{"id":5,"lob":"ENG","product":"stick","title":"a magic stick"},
{"id":6,"lob":"ENG","product":"door","title":"a door"},
{"id":7,"lob":"IT","product":"mobile","title":"32-bit app"}, 
]

and then please see below for the expected output:


[
    {
      lob: "IT",
        product: [
            {
            name: "mobile",
            titles: [
                    {
                        title: "64-bit app",
                    },
                    {
                        title: "32-bit app",
                    }
                ]
            },
            {
                name: "laptop",
                titles: [
                        {
                            title: "this is laptop",
                        },
                        {
                            title: "another laptop",
                        }
                    ]
                }
            
        ]
    },
    {
        lob: "ENG",
          product: [
              {
              name: "stick",
              titles: [
                      {
                          title: "64-bit app",
                      },
                      {
                          title: "32-bit app",
                      }
                  ]
              },
              {
                  name: "laptop",
                  titles: [
                          {
                              title: "a magic stick",
                          },
                          {
                              title: "a door",
                          }
                      ]
                  }
              
          ]
      }

]

How do I achieve this using javascript, or are there any package/library i can use.