I am new to javascript / html and have some problems to understand the import / module functionality. I need to load a json file into javascript.
The best way I could find is via import, like:
import myJason from './dummy.json' assert {type: 'json'};
When trying it, I am getting following error:
Cannot use import statement outside a module
So I placed it into a module (tried header and body). But I am not able to access the module functions.
Google could not help me, could please somebody explain how to do it properly.
Note: HTML and JSON files are local files (not accessed via Webserver)
Here is the (reduced) code:
<html lang="en">
<head>
<script type="module">
import myJason from './dummy.json' assert {type: 'json'};
function dummy(){
//evaluate JSON
return result();
}
window.dummy = dummy;
export{dummy}
</script>
</head>
<body>
<script>
// tried (and other things)
// dummy();
// window.dummy();
</script>
</body>
</html>