<input name='users[123][name]'/>
{
...
'users[123][name]': value_input,
...
}
users: {
123: {
name: value_input
}
const serialize = (form) => {
const obj = {};
const inputs = [...form.querySelectorAll('input')];
inputs.forEach((input) => {
const params = input.name.match(/(?<=\[)\S+?(?=\])|^\S+?(?=\[)/g);
const value = input.value;
params.reduce((current, param, i, arr) => {
if (!obj[param]) current[param] = {};
if (i === arr.length - 1) current[param] = value;
return current[param];
}, obj);
});
return obj;
};