If you only needed to have the <
and >
encoded again, setting the flag JSON_HEX_TAG
while re-encoding the data, would do.
If you want something that leaves all such unicode escape sequences in place … then you need to replace each \uXXXX
with \\u0075XXXX
first, then manipulate and re-encode your data – and then replace \u0075
with just u
again at the end:
$json = preg_replace('#\\\\u([0-9A-F]{4})#', '\\\\\u0075$1', $json);
$dec = json_decode($json, true);
$enc = preg_replace('#\\\\u0075#', 'u', json_encode($dec));
If you do it like this, then you of course got to be aware, that your data now contains literal \uXXXX
sequences. Meaning, if you wanted to replace <
in one of the object’s string values now, you can’t search for <
, but would need to search for \u003C
.