Read Property Values in Cypress_Json File

143 Views Asked by At

I am trying to reach out to the "testdata":"two" property values [like 'EH']. While I was taking that property, I am facing "Cannot read property" this issue, How I fix this issue in Cypress?

[{
        "testdata": "one",
        "TC": {
            "EHQ0": "Address",
            }

    },
    {
        "testdata": "two",
        "TC": {
            "EH": "Student",
            "E1": "Question For Name",
            "EnglishText_E1": "Question For Name"
        }

    }
]
1

There are 1 best solutions below

4
On

You have an array of objects, so either index or find.

const data = [{
        "testdata": "one",
        "TC": {
            "EHQ0": "Address",
            }

    },
    {
        "testdata": "two",
        "TC": {
            "EH": "Student",
            "E1": "Question For Name",
            "EnglishText_E1": "Question For Name"
        }

    }
]

const objTwo = data.find(obj => obj.testdata === 'two')
const ehProp = objTwo.TC.EH