<?php
$php_JSON_str =
'{"version":"1.00",
"data":[
{"name":"Ted","hair-color":"broun"},
{"name":"Gideon","height":"6 feet"}
]
}';
?>
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Read JSON object from database using JavaScript</title>
</head>
<body>
<div align="center">
<h1>It is recommended to see the source of the page.<br>
Right-click and select view page source</h1>
<div id="show"></div>
<script>
js_object = <?php echo $php_JSON_str ?>; // no apostrophes there for it is a JSON Object
str = "<hr>";
for (i=0 ; i < js_object.data.length ; i++ ) {
one_obj = js_object.data[i];
for (k in one_obj) {
str += k + " : " + one_obj[k] + "<br>";
}
str += "<hr>";
}
document.getElementById("show").innerHTML = str;
</script>
</div>
</body>
</html>