php - Code Challenge: Convert var_dump of array to json -


i have never thought until today, after searching web didn't find anything. maybe wasn't wording right in search.

given nested array var_dumped

<pre>array(3) { 'id' =>  string(19) "as-agent-to-shipper" 'name' => string(19) "as-agent-to-shipper" 'children' => array(1) { [0] => array(3) {   'id' =>   string(28) "agility-logistics-s-a-de-c-v"   'name' =>   string(30) "agility logistics s.a. de c.v."   'data' =>   array(2) {     'band' =>     string(22) "-as agent shipper -"     'relation' =>     string(13) "buyer of band"       }     }   } } 

the challenge this: best optimized method converting var_dumped array json? matter of regex? or there other way? looking creativity.

it impossible parse structure using regex.

it possible write specialized parser it, given php makes no promises on format, bad idea so. in minor php version update format change , parser stop working.

even more, var_dump lossy, there cases when can not recover state of object representation. simplest example resources. var_dumping open file returns resource(5) of type (stream), not enough useful it.

all in all, sounds bad idea, , whatever problem solved it, should solved differently.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

debian - 500 Error upon login into Plesk Admin - auth.php3? -