jeudi 21 novembre 2019

Getting undefined values from my .json file/ First time js node user

I'm not to JS node and am having a problem with using my test fixture (a .json file). Here is my .json file:

{
"info": [
    {
        "type": "person",
        "gender": "Male",
        "altUrl": "http://www.testUrl.com",
        "contact": {
            "email": {
                "type": "Work",
                "address": "testEmail@email.com",
            },
            "phone": {
                "type": "Mobile",
                "number": "8989898989"
            }
        }
    }
]}

And in my .js file I have: var account = require('../../myfile.json');

The problem is, when I try to access the data from my .json file, it always comes back as undefined. An example of me calling the .json file is: console.log(account.info.gender);

Does anyone have any ideas as to why I'm getting undefined values? Any help would be greatly appreciated! Thank you

Aucun commentaire:

Enregistrer un commentaire