Fijate si te sirve algo así:
Código php:
Ver original<?php
if(isset($_GET['algo'])){ }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin título</title>
<script>
var objeto = {nivel:'A', nombre:'Costa Sur', personal:'145',algo:{pepe:123},otro:['a','b']};
function print_JS(){
this.a='';
this.recorrer=function(o){
if(o.constructor==Array)
this.a+='[';
if(o.constructor==Object)
this.a+='{';
for(var i in o){
if(o.constructor!=Array)
this.a+='"'+i+'":';
if(o[i].constructor==Object){
this.recorrer(o[i]);
}else if(o[i].constructor==Array){
this.recorrer(o[i]);
}else if(o[i].constructor==String){
this.a+='"'+o[i]+'",';
}else{
this.a+=o[i]+',';
}
}
if(o.constructor==Object)
this.a+='},';
if(o.constructor==Array)
this.a+='],';
return this.a.substr(0,this.a.length-1).split(',}').join('}').split(',]').join(']');
}
}
onload=function(){
var r=new print_JS();
document.getElementById('algo').value=r.recorrer(objeto);
}
</script>
</head>
<body>
<form name="form1" method="get" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<textarea name="algo" rows="5" id="algo"></textarea>
<input type="submit" name="Submit" value="Enviar">
</form>
</body>
</html>