JSON is a multidimensional-array, the easiest way to view it, in my opinion, is to just
var_dump($json_array);
Though, this may be the chunk of data you're referring to.
It's not a very table friendly format, as a table is inherently 2-dimensional, and JSON can be many-dimensional.
You can flatten the array, and then display it as a table.
function flatten_json($json, &$flat, $key) {
// First check the base case: if the arg is not an array,
// then it's data to be inserted in the flat array.
if (!is_array($json)) {
$flat[$key] = $json;
} else {
// It's an array, to reduce the depth of the json,
// we remove this array, by iterating through it,
// sending the elements to be checked if they're also arrays,
// or if they're data to be inserted into the flat array.
foreach ($json as $name => $element) {
flatten_json($element, $flat, $key.'_'.$name);
}
}
}
To use this function, you first declare you flat array:
$flat = array();
Then pass it to the function, with your json, and a key you want to be the outer key, if you are sure that your json is an array, which is pretty much guaranteed, you can leave the key empty.
flatten_json($json_array, $flat, '');
Now $flat will have the flattened json, and you can print it as a table, maybe into a csv if you have many json results to print.
If your json was:
array(
'person' => array(
'name' => 'timmy',
'age' => '5'
),
'car' => array(
'make' => 'ford',
'engine' => array(
'hp' => 260,
'cyls' => 8
)
)
)
Then $flat will look like:
array(
'person_name' => 'timmy',
'person_age' => 5,
'car_make' => 'ford',
'car_engine_hp' => 260,
'car_engine_cyls' => 8
)
and if you wanted printed in a nice html table:
echo "<table><tr>";
foreach ($flat as $header => $value) {
echo "<th>$header</th>;
}
echo "</tr><tr>";
foreach ($flat as $header => $value) {
echo "<td>$value</td>";
}
echo "</tr></table>";
DOMDocumentor similar and for jsonjson_decodeis enough.print_r()in a nicer format you can view the HTML source in the browser, as the browser will render ignoring whitespace formatting so it will all show up in a giant blob of text. Or you can do thisecho '<pre>' . print_r($your_decoded_json) . '</pre>';