I have this clever little piece of vanilla Javascript that converts url params into a hash:
"a=a&b=b".split("&").reduce((function(params, param) {
var param_split = param.split("=").map(function(value) {
return decodeURIComponent(value.replace("+", " "));
});
params[param_split[0]] = param_split[1];
return params;
}), {});
Which outputs this hash:
{
a: "a",
b: "b"
}
But sometimes I get url params that are nested like this:
"a=a&b%5Bc%5D=bc&b%5Bd%5D=bd"
My script would output:
{
a: "a",
b[c]: "bc",
b[d]: "bd"
}
What should I do in order to be able to output a nested hash like this?:
{
a: "a",
b: {
c: "bc",
d: "bd"
}
}