[php] json_encode() escaping forward slashes

I'm pulling JSON from Instagram:

$instagrams = json_decode($response)->data;

Then parsing variables into a PHP array to restructure the data, then re-encoding and caching the file:


When I open the cache file all my forward slashes "/" are being escaped:


I gather from my searches that json_encode() automatically does this...is there a way to disable it?

This question is related to php json

The answer is

Yes, but don't - escaping forward slashes is a good thing. When using JSON inside <script> tags it's necessary as a </script> anywhere - even inside a string - will end the script tag.

Depending on where the JSON is used it's not necessary, but it can be safely ignored.

I had to encounter a situation as such, and simply, the


did work for me.

On the flip side, I was having an issue with PHPUNIT asserting urls was contained in or equal to a url that was json_encoded -

my expected:


would be encoded to:


If you need to do a comparison, transforming the url using:

addcslashes($url, '/')

allowed for the proper output during my comparisons.