I have string
in the following format:
"a=123 b="ABC" c="Olá Mundo!""
I need to create a function that transforms this string into this json:
{
a : 123,
b : "ABC",
c : "Olá Mundo!"
}
I think it has a bit of regular expression and a split (), but I know almost nothing about RegEx.
I was developing this function, but I did not get much success.
function strToJson(str) {
var json = {};
var str_split = str.split(" ");
var str_split_value = [];
for (var i in str_split) {
str_split_value = str_split[i].split("=");
json[str_split_value[0]] = str_split_value[1];
}
return json;
}
console.log(strToJson('a=123 b="ABC" c="Olá Mundo!"'));