This is my code, but for some reason it does not show the requested data .. I would like to see you if I am doing something wrong.
PHP
<?php
$var1 = 1;
$var2 = 2;
$var3 = 3;
$myobj -> foo1 = $var1;
$myobj -> foo2 = $var2;
$myobj -> foo3 = $var3;
$json = json_encode( $myobj, true );
?>
javascript:
<script>
var json = <?php echo "$json"; ?>;
document.getElementById("ID").innerHTML = json.foo2;
</script>