note 106726 deleted from function.json-decode by googleguy

From: Date: Fri, 30 Nov 2012 05:46:31 +0000
Subject: note 106726 deleted from function.json-decode by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-192222@lists.php.net to get a copy of this message
Note Submitter: sjungwirth at gmail dot com ---- My way to replace single quotes around values <?php $json = <<<STR {"key":'val',"key's":'O\\'Brian\'s', "key\"quotes\"" : 'Jimmy "the rock" Michael\'s'} STR; $json = preg_replace('/:\s*\'(([^\']|\\\\\')*)\'\s*([},])/e', "':'.json_encode(stripslashes('$1')).'$3'", $json); print_r(json_decode($json, TRUE)); /** * Array * ( * [key] => val * [key's] => O'Brian's * [key"quotes"] => Jimmy "the rock" Michael's * ) */ ?> combine this with previous posters way to enclose keys in double quotes and you have a loose json_decode function that can handle javascript object syntax: {key:'', ...}

« previous php.notes (#192222) next »