Skip to content
Advertisement

Read JSON that is in website source in client-side vanilla javascript

I have a simple JSON file sitting in a data folder within the source of my website. In a javascript script I want to read the JSON and update the DOM with the information inside. The file structure of my website is like this

JavaScript

I obviously can’t use require() from nodejs because this is on the client side. I don’t see how FileReader would work here. All I need to do is read this JSON file from ../src/data/jsonFile.json.

Advertisement

Answer

I meant the third answer, you can use fetch statement. If you are confused about fetch then I recommend you look it up online first.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement