You have the option to quickly convert your code using regex, but it may not be the safest method. Consider using a loop for parsing objects instead:
let obj = {
"players": "a:36:{i:0;a:3:{s:9:\"player_id\";i:108035;s:4:\"team\";s:5:\"team1\";s:4:\"role\";s:4:\"main\";}i:1;a:3:{s:9:\"player_id\";i:134595;s:4:\"team\";s:5:\"team1\";s:4:\"role\";s:4:\"main\";}i:2;a:3:{s:9:\"player_id\";i:107807;s:4:\"team\";s:5:\"team1\";s:4:\"role\";s:4:\"main\";}}",
"events": "a:13:{i:0;a:7:{s:4:\"type\";s:4:\"goal\";s:4:\"team\";s:5:\"team2\";s:4:\"time\";i:10;s:6:\"player\";s:11:\"David Silva\";s:4:\"note\";s:14:\"Bernardo Silva\";s:9:\"player_id\";i:107941;s:10:\"player2_id\";i:107952;}}",
"stats": "a:17:{i:0;a:3:{s:5:\"title\";s:12:\"Yellow cards\";s:5:\"team1\";i:2;s:5:\"team2\";i:3;}}"
}
// This code can be enhanced with a loop for parsing
Object.values(obj).forEach((str) => {
str = "{" + str + "}";
str = str.replace(/([asi](?:\:[0-9]+)*):/g, '"$1":');
str = str.replace(/;/g, ',');
str = str.replace(/}"/g, '},"');
str = str.replace(/,}/g, '}');
str = str.replace(/"i":([0-9]*),"(a:[0-9]+)":{/g, '"$2_$1":{');
console.log(JSON.parse(str))
});
Parsed Output :
{
"a:36": {
"a:3_0": {
"s:9": "player_id",
"i": 108035,
"s:4": "main",
"s:5": "team1"
},
...
}
}
{
"a:13": {
"a:7_0": {
"s:4": "note",
"s:5": "team2",
"i": 107952,
"s:6": "player",
...
}
}
}
{
"a:17": {
"a:3_0": {
"s:5": "team1",
"s:12": "Yellow cards",
"i": 2
},
...
}
}