TechJunkie TechJunkie - 1 year ago 52
JSON Question

Checking If Specific JSON Key at a Specific Dynamic Location is Null (error)

I am receiving a JSON object back from a server and am looping through the object to gather certain information. I first need to check if a certain key exists in the object at a specific location. I'm doing this as follows:

if (dataJSONobj.responseText['ops:world-patent-data']['ops:equivalents-inquiry']['ops:inquiry-result'][i]['exchange-documents']['exchange-document']['bibliographic-data']['references-cited']['citation'][j]['nplcit'])
//the key is in there

However, I am getting this error every time:

CaseSelector.js:322 Uncaught TypeError: Cannot read property 'nplcit' of undefined*** when there is not a "nplcit" key.

What am I doing wrong with my syntax? I've even tried the reverse by asking if that key is not equal to

Answer Source

['citation'][j] does not exist, which if this is only happening when you know that there is no nplcit key, there is probably some correlation between the two. But regardless of if nplcit exists or it doesn't, ['citation'][j] does not.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download