[wiki] Convert JSON data to html table for display on page


I have a calls which help me display json directly in html table.
Json2Table::formatContent($json);

The code of Json2Table class is here
============================================
/**
* Class convert Json to html table. It help view json data directly.
* @author shiv
*
*/
class Json2Table
{

public static function formatContent($content, $class = 'table table-bordered')
{
$html = "";
if ($content != null) {
$arr = json_decode(strip_tags($content), true);

if ($arr && is_array($arr)) {
$html .= self::arrayToHtmlTableRecursive($arr, $class);
}
}
return $html;
}

public static function arrayToHtmlTableRecursive($arr, $class = 'table table-bordered')
{
$str = "";
foreach ($arr as $key => $val) {
$str .= "";
$str .= "$key";
$str .= "";
if (is_array($val)) {
if (! empty($val)) {
$str .= self::arrayToHtmlTableRecursive($val, $class);
}
} else {
$val = nl2br($val);
$str .= "$val";
}
$str .= "";
}
$str .= "";

return $str;
}
}