json_decode double quotes and commas returns NULL

json, php

Solution

My problem was fixed by replacing stripslashes() with urldecode(). This happened because someone previously made use of urlencode().

$jsonFix = urldecode($json);
$json = json_decode($jsonFix, true);

Problem

I'm trying to use json_decode to decode a json that contains a word with a comma and a word with double quotes: ``` {"wordsFont":"Times New Roman","nameList":["Overflow ,","Stack ""]} ``` json_decode fails so i tried to format the string to escape the quotes with functions like: ``` function fixDoubleQuotedJSON($broken_json) { return str_replace('""','\""',$broken_json); } ``` but it's only the case where the comma and double quotes are at the end of a word. And the outcome: ``` {"wordsFont":"Times New Roman","nameList":["Overflow \,","Stack \""]} ``` decodes correctly but i need to find a way to do that for any placement of double quotes and commas. any suggestions? EDIT: this is the initial value in the database: ``` {\"wordsFont\":\"Times New Roman\",\"nameList\":[\"Overflow ,\",\"Stack \\\"\"]} ``` and i can't change the code that generates it to the database

Original source