I need to use some JSON data from external local file.
For me, the easiest way to do that is to make a string of JSON text and turn it into javascript object, like that:
<script type="text/javascript" src="teachers.json"></script>
<script>
var data = JSON.parse(p);
alert(data[0].name);
</script>
and JSON file:
var p = `[
{
"name" : "Anna",
"age" : "45"
},
{
"name" : "Bill",
"age" : "52"
}
]`;
But I'd like to work with real JSON like
myObj = { "name":"John", "age":"31"};
How can I use json from external local file without using jQuery?
var
in a JSON file?