If you want to achieve this task, the key is performing a series of replacements, aided by a helper function:
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
Next, execute the replacements and utilize JSON.parse
:
JSON.parse(
'[ key = 1542633482511430199, value=>>>BasicData:isConfirmAndOrder=0,brmRequestId=BR-2018-0000124,requestType=batch,projectName=Automation_Product_By_Admin,projectId=PRJ-2018-0000477,department=Global Packaging]'
.replace(':', ':{').replace(']', '}}')
.replace(':', ':{').replaceAll("=", ':"')
.replaceAll(",", '",')
.replace(':"', ":")
.replace('[', '{')
.replace("}}", '"}}}')
.replace('",', ",")
.replace('>>>', '{')
.replace('{{', '{')
.replace('value:"', "value:")
.replace("=", ":")
.replace('key :', '"key" :')
.replace('value:', '"value":')
.replace('BasicData:', '"BasicData":')
.replace('isConfirmAndOrder:', '"isConfirmAndOrder":')
.replace('brmRequestId:', '"brmRequestId":')
.replace('requestType:', '"requestType":')
.replace('projectName:', '"projectName":')
.replace('projectId:', '"projectId":')
.replace('department:', '"department":')
)