Use json_decode
to parse json, then iterate over the result...
echo "<table>\n";
$data = json_decode($json, true);
foreach($data as $key=>$value) echo "<tr><td>{$key}:</td><td>{$value}</td></tr>\n";
echo "</table>\n";
Note that this will work only for such "simple" json objects as you gave in example...
If theres multi-level nesting, this won't be enough. You will have to check the type of $value
and decide how to print it at any level of nesting...
Also note, that json string can also be not an object at all. It can also be a primitive type.
Ultimately, you either have a multidimensional array, or an object (if you ommit the second parameter from json_decode
call). From that point on, the 'goal' changes from pretty-print a json object into pretty-print a php variable. There are plenty of solutions for that.