How can I fetch a local JSON file that is in my directory?
the JSON file looks like this:
[ { "name": "Sara", "id": 3232 }, { "name": "Jim", "id": 2342 }, { "name": "Pete", "id": 532532 } ] If I have the json information inside the same file I'm trying to use it, it works beautifully, but if I want to bring it in, I can't for the life of me get it to work and it keeps reading it as undefined.
here is what I have
getData() { var json_data = require('../services/contributors.JSON'); for (var i in json_data){ console.log('Name: ' + json_data[i]["name"]) } } Can you see what I'm doing wrong? I'm trying to get this into react so maybe react works differently? I don't know. Any help will be appreciated. Thank you!
requireto the top of your file, outside of the component