<html>
<head>
<script>
window.onload = function() {
var jsonValue={
"name": "Chris",
"age": "RIP",
"musketeers": ["Athos", "Aramis", "Porthos", "Artagnan"],
"stooges": [
{ "name": "Moe" },
{ "name": "Larry" },
{ "name": "Curly" }
],
"name details": {
"first": "Michael",
"last": "Jackson"
}
};
if (!Array.prototype.inArray) {
Array.prototype.inArray = function(element) {
return this.indexOf(element) > -1;
};
}
var key,key1,key2,innerdiv = '';
var array = ['0','1','2','3','4','5','6','7','8','9','10','11'];
for(key in jsonValue){
if(jsonValue.hasOwnProperty(key)) {
if(typeof(jsonValue[key])=='object'){
innerdiv+="<div>"+key;
for(key1 in jsonValue[key]){
if(jsonValue[key].hasOwnProperty(key1)){
innerdiv+= "<p>";
if(typeof(jsonValue[key][key1]) =='object'){
for(key2 in jsonValue[key][key1]){
innerdiv+= key2 + " <input type='text' name='"+key2+"' value='"+jsonValue[key][key1][key2]+"'></p>";
}
}
else{
if(array.inArray(key1)){
innerdiv+= " <input type='text' name='"+key1+"' value='"+jsonValue[key][key1]+"'></p>";
}
else{
innerdiv+= key1 + " <input type='text' name='"+key1+"' value='"+jsonValue[key][key1]+"'></p>";
}
}
}
}
innerdiv+="</div>";
}
else{
innerdiv+= "<p>"+key+" <input type='text' name='"+key+"' value='"+jsonValue[key]+"'></p>";
}
}
}
document.getElementById("htmlContent").innerHTML = innerdiv;
};
</script>
</head>
<form name="" action="" method="">
<div id="htmlContent"></div>
<input type="submit" name="submit" value="submit">
</form>
</html>