javascript – Converting one json object to another with jquery

i have an input json object , and i want the below output json from a jquery function . How can i achieve it with min lines of code .

Input

{
    "dashboardWidgetFacility": [{
        "deskUsageInput": {
            "breakup": [{
                "location_breakup_0": ["{\"id\":1,\"name\":\"campus\"},{\"id\":8,\"name\":\"building \"}"],
                "teams_breakup_0": ["3", "6"]
            }, {
                "location_breakup_1": ["{\"id\":1,\"name\":\"campus\"},{\"id\":8,\"name\":\"building \"},{\"id\":83,\"name\":\"floor \"}"],
                "teams_breakup_1": ["3", "2"]
            }]
        }
    }]
} 

Output Object

{
    "dashboardWidgetFacility": [{
        "campus": {
            "id": 1
        },
        "building": {
            "id": 8
        },
        "widgetInput": {
            "deskUsageInput": {
                "teams": ["3", "6"]
            }
        }
    }, {
        "campus": {
            "id": 1
        },
        "building": {
            "id": 8
        },
        "floor": {
            "id": 83
        },
        "widgetInput": {
            "deskUsageInput": {
                "teams": ["3", "2"]
            }
        }
    }]
}

Here location breakup location_breakup_{index} , has the index.

Read more here: Source link