I am having the following JSON(invalid) as a string. I need to parse it and get the inner value. I tried a lot but didn't get the result.
$sJson = '{"Place":"MyStore","PurchaseID":"IND.1234-5678-9012-34567","details":"{\"json\":\"{\\\"PurchaseID\\\":\\\"IND.1234-5678-9012-34567\\\",\\\"categoryname\\\":\\\"smartpack\\\",\\\"productname\\\":\\\"bitcoinpack1\\\",\\\"purchaseTime\\\":1504256011148,\\\"purchaseState\\\":\\\"Success\\\",\\\"UniqueToken\\\":\\\"jbbefjifdkpdpajfkomckoof.AO-J1OzEdsZX17M5pAvedDh1Ep_WwlOKamMQN_3O89bRbAPX-uoqPpTJf8EdNcjMhCK1dptGaWReUCSS9JGCJuh6GlAT0l11mkUddo_uJ4YOe8ezYxlmDQ8\\\"}\",\"currentvalue\":\"S270U2J3XF\\/+XnC1ocPp0d\\/Kwf\\/4B\\/\\/tT7urbDn6F+\\/D8j7VD1t8qqwevtKDnAafAtvocPg4Eevkf\\/GZKl1YOgUYyuY63nyekz7GRDuIKVXAZ+iZtPAbwCuwZplUQHaVA\\/EBMjYpPQM0EFtp2WuX\\/Tx9nTnFCtU+gAK4Rg0zLvQNKSJx5WfqhK7wf0wHTTYviTkB\\/pETnkV22oQDIZH9\\/Fy1FXltC7FXHXoMcxtGvkgPSEFOnms4HumjUQ5PtQUbxh\\/oirQeROCAhkO+WKX9WO3bCKjru1uuxspTLCNGJEKAezi2GEBcpFGjq4iS5N7SfO5BOF76\\/joLe3B7OemJNw==\"}"}';
$sJson = json_encode($sJson,JSON_UNESCAPED_SLASHES);
$json_array = (array) json_decode($sJson,true);
$newjson=preg_replace('/.+?({.+}).+/','$1',$json_array);
var_dump($newjson);
exit;
The Result $newjson
is not return as JSON Object, it gives as only string.
I need JSON object not a string.
In the given JSON, json
value is a string(inside valid JSON) which starts with "
.
I need to remove this.