I am currently using HTML/PHP to get a JSON file from an API. I then want to manipulate the JSON file in JavaScript and display certain elements of the JSON on the page. I can see that the JSON is being bought back correctly, but I cannot save the JSON into a JavaScript variable after this. My code is below.
<?php
$pokemon = $_POST['pokemon'];
$siteaddressAPI = "http://pokeapi.co/api/v1/game/" . $pokemon . "/";
$data = file_get_contents($siteaddressAPI);
echo($data)
?>
<!DOCTYPE HTML>
<html>
<body>
<br><br><br><br><br><br><br>
<p>Created: <span id="created"></span><br></p>
<script>
var txt = <?php echo ($data); ?>;
obj = JSON.parse(txt);
document.write("<p>Created: " + obj.created + "</p>");
</script>
</body>
</html>
EDIT: I have just noticed my lack of ' ' around my txt variable, this has now been fixed but the issue remains.

JSON.parse, remove it. (And rename your variabletxttoobjin the first place, because that is what you are getting when your JSON code gets interpreted by the JS engine.)