Take the 2-minute tour ×

Possible Duplicate:
JSON: why are forward slashes escaped?

The function argument below is a string run through json_encode(). I see that the forward slash in http:// is escaped to http:\/\/. Obviously it is a special character when used like this <some_tag></some_tag> but only when used in that structure.

There is no immediate problem..but I need to understand escapes to make some code updates.

<script type='text/javascript'>Arc.ViewHBookmark('[{"id":"1","0":"1","title":"cybercoders","1":"cybercoders","url":"http:\/\/cybercoders.com","2":"http:

php.net - json_encode


JSON: why are forward slashes escaped?

share|improve this question

marked as duplicate by mcgrailm, Juhana, rdlowrey, Felix Kling, Andy E Feb 20 '12 at 16:04


1 Answer 1

up vote 4 down vote accepted

It is just as a safety net for the </endtag> structure for JSON embedded in <script> elements in HTML documents.

It has no other significance.

share|improve this answer
In JSON "\/" means the same as "/". The escape sequence doesn't depend on being near any other characters. The escape character isn't ignored, it escapes the character that follows it, the sequence just doesn't have any special meaning. –  Quentin Feb 20 '12 at 16:10
...the only characters that need to be escaped in an encoding mechanism are the special characters used in the encoding mechanism structure itself( for JSON that would be ", {,},[,], etc.)...all other characters are payload and should be treated as such... –  user656925 Jun 1 '12 at 21:02
@HiroProtagonist — The developers of PHP's json_encode function disagree. –  Quentin Jun 1 '12 at 21:15
The developers of PHP thought for a very long time that having magic_quotes is a good thing; they apparently still do, in the narrower context of json_encode, because that's exactly what this is: magic quotes. –  lanzz Dec 3 '12 at 9:24
@lanzz — There is a huge difference between adding an escape that never changes the meaning of the data (in the context of JSON) and adding an escape without any regard for what will be done with the data. –  Quentin Dec 3 '12 at 9:26