I need to print a string JSON
from PHP
within value
of a input
, to then be able to recover it with JavaScript
.
<?php
$array = array(
"foo" => "bar",
);
$json = json_encode($array);
?>
<input id="input" value="<?php echo $json; ?>" />
<script>
let json = JSON.parse(document.getElementById('input').value);
console.log(json);
</script>
What would I have to do to print the JSON
and then be able to recover it from JavaScript
?