I have an array of objects containing all the form data. However, I need to format this data differently before sending it to the backend. Each object needs to be fetched separately and then pushed into another object as shown below. The current data looks like this:
[
{
"messageType": "test",
"eligibleUsers": "test2",
"rules": [
{
"ruleId": "qwer",
"value": "qwert"
},
{
"ruleId": "testing",
"value": "testing"
},
{
"ruleId": "newtest",
"value": "newtesting"
}
]
},
{
"messageType": "add",
"eligibleUsers": "newadd",
"rules": [
{
"ruleId": "qaz",
"value": "qaz"
}
]
},
{
"messageType": "neww",
"eligibleUsers": "add",
"rules": [
{
"ruleId": "data",
"value": "data1"
},
{
"ruleId": "data2",
"value": "dat3"
}
]
}
]
However, I would like the data to be structured like this:
{
"questions": [
{
"id": null,
"ques": "test",
"type": "dropdown",
"message_user_type": "self",
"rules": [
{
"rule": "qwer"
},
{
"rule": "testing"
},
{
"rule": "newtest"
}
]
},
{
"id": null,
"ques": "test2",
"type": "dropdown",
"message_user_type": "emp",
"rules": [
{
"rule": "qwert"
},
{
"rule": "testing"
},
{
"rule": "newtesting"
}
]
},
{
"ques": "add",
"rules": [
{
"rule": "qaz"
}
]
},
{
"ques": "newadd",
"rules": [
{
"rule": "qaz"
}
]
},
{
"ques": "neww",
"rules": [
{
"rule": "data"
},
{
"rule": "data2"
}
]
},
{
"ques": "add",
"rules": [
{
"rule": "data"
},
{
"rule": "data2"
}
]
}
]
}
I would appreciate any assistance with this! Thank you in advance.