I had a Response coming like a JSON array like below and I need to sort out the JSON containing the same roleId and TenantId and send them with all the features in the same array.
[
{
"roleId": 1,
"role": "admin",
"featureId": 1,
"feature": "Dashboard",
"tenantId": 1,
"tenant": "Admin"
},
{
"roleId": 1,
"role": "admin",
"featureId": 2,
"feature": "Overview",
"tenantId": 1,
"tenant": "Admin"
},
{
"roleId": 1,
"role": "admin",
"featureId": 3,
"feature": "Devices",
"tenantId": 1,
"tenant": "Admin"
},
{
"roleId": 1,
"role": "admin",
"featureId": 4,
"feature": "Map View",
"tenantId": 1,
"tenant": "Admin"
}
]
I need to customize it and return as a response like below grouping by tenantid and role in a sub json
{
"roleId": 1,
"role": "admin",
"features": [
{
"featureId": 1,
"feature": "Dashboard"
},
{
"featureId": 2,
"feature": "Overview",
},
{
"featureId": 4,
"feature": "Map View",
},
{
"featureId": 3,
"feature": "Devices",
}
],
"tenantId": 1,
"tenant": "Admin"
},
{
"roleId": 2,
"role": "monitor",
"features": [
{
"featureId": 1,
"feature": "Dashboard"
},
{
"featureId": 2,
"feature": "Overview",
},
{
"featureId": 4,
"feature": "Map View",
},
{
"featureId": 3,
"feature": "Devices",
}
],
"tenantId": 1,
"tenant": "Admin"
}
Expected UI should be something like below after integration
Please help me out in this
Thanks in advance
feature,featureId... etc]. See here:- 3v4l.org/Ze2SY