I want to serialise a date with the /
character in JSON, but I get this one escaped by a \
.
$a['0'] = '25/11';
echo json_encode($a); // ["25\\/11"]
and obviously i want to get ["25/11"]
I want to serialise a date with the /
character in JSON, but I get this one escaped by a \
.
$a['0'] = '25/11';
echo json_encode($a); // ["25\\/11"]
and obviously i want to get ["25/11"]
["25\/11"]
and ["25/11"]
are different representations of exactly the same data in JSON, so you (effectively) already have ["25/11"]
.
The solution then is: do nothing.
In JSON, /
can be escaped, but does not need to. The fact that you get \/
just means that the serialization unit decides to escape it. The meaning is the same, so if you care about that it is fine as it is.
If you want the serialization to look different, however, there might be a setting to control this. Otherwise you need a different serialization module. Or you postprocess the generated serialization string, which, however, I don't recommend.