note 91656 deleted from function.json-decode by salathe

From: Date: Mon, 21 Sep 2020 15:01:40 +0000
Subject: note 91656 deleted from function.json-decode by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-215437@lists.php.net to get a copy of this message
Note Submitter: premiersullivan at gmail dot com ---- This function will remove trailing commas and encode in utf8, which might solve many people's problems. Someone might want to expand it to also change single quotes to double quotes, and fix other kinds of json breakage. <?php function mjson_decode($json) { return json_decode(removeTrailingCommas(utf8_encode($json))); } function removeTrailingCommas($json) { $json=preg_replace('/,\s*([\]}])/m', '$1', $json); return $json; } ?>

« previous php.notes (#215437) next »