You can convert the string to a collapsible format with str_replace . Then parse_str into an array. It does not guarantee operation for all returned rows, but answers your question.
<?php
$str = 'Details: [fieldPath: id; trigger: Invalid predicate name: id; errorString: SelectorError.INVALID_PREDICATE_FIELD_NAME]';
// strip out details and []
$str = str_replace(['[',']', 'Details:'], '', $str);
// fix name and replace seperators
$str = str_replace([': ', ';', ' name='], ['=', '&', '&name='], $str);
// parse string into $array variable
parse_str($str, $array);
$json = ['Details' => $array];
print_r(json_encode($json, JSON_PRETTY_PRINT));
https://3v4l.org/nKa6b
Result:
{
"Details": {
"fieldPath": "id",
"trigger": "Invalid predicate",
"name": "id",
"errorString": "SelectorError.INVALID_PREDICATE_FIELD_NAME"
}
}
source
share