Java use streams map to return desired JSON Structure

I’m new to Java I have an array like below

[{'roleName': "driver", "name": "Hub"},{'roleName': "hoc", "name": "Org"},{'roleName': "hubManager", "name": "Hub"}]

I have to format the same into below structure

    Org :{
        role : ["hoc"]
    Hub: {
        role :

Please help me how we can do this with Java streams

I have tried the below

List<String> roles = roleLevels
                .map(c -> c.getRoleName()).collect(Collectors.toList());

But that’s not the expected result


Use groupingBy with downstream Collector:

Map<String, List<String>> result =

Source: stackoverflow