JSON child objects return undefined values

advertisements

I have JSON with different child objects (scans) shown below. I am trying print contents of child objects with javascript, it gives me an output 'undefined'.

JS Fiddle link: https://jsfiddle.net/jpavanaryan/sz5gkesh/

 alert(jsonobj.scans[0]);

 var jsonobj={
           "scan_id": "004d396404ae9343e1479689c05d02290babdf14f502b3437e247e02e74ba803-1490201685",
           "resource": "http://helenphilwarnes.com/ymal/image.htm",
           "url": "http://helenphilwarnes.com/ymal/image.htm",
           "response_code": 1,
           "scan_date": "2017-03-22 16:54:45",
           "permalink": "https://www.virustotal.com/url/004d396404ae9343e1479689c05d02290babdf14f502b3437e247e02e74ba803/analysis/1490201685/",
           "verbose_msg": "Scan finished, scan information embedded in this object",
           "filescan_id": "fb2d9f058c2010c57f86a05ae33d282f33e3825290c66b8b120cd177416c6bdf-1489446422",
           "positives": 15,
           "total": 64,
           "scans":    {
              "CLEAN MX":       {
                 "detected": false,
                 "result": "clean site"
              },
              "Rising":       {
                 "detected": false,
                 "result": "clean site"
              },
              "OpenPhish":       {
                 "detected": true,
                 "result": "phishing site"
              },
              "VX Vault":       {
                 "detected": false,
                 "result": "clean site"
              },
              "ZDB Zeus":       {
                 "detected": false,
                 "result": "clean site"
              },
              "ZCloudsec":       {
                 "detected": false,
                 "result": "clean site"
              },
              "PhishLabs":       {
                 "detected": false,
                 "result": "unrated site"
              },
              "Zerofox":       {
                 "detected": false,
                 "result": "clean site"
              },
              "K7AntiVirus":       {
                 "detected": false,
                 "result": "clean site"
              },
              "SecureBrain":       {
                 "detected": false,
                 "result": "clean site"
              },
              "Quttera":       {
                 "detected": false,
                 "result": "clean site"
              },
              "AegisLab WebGuard":       {
                 "detected": false,
                 "result": "clean site"
              },
              "MalwareDomainList":       {
                 "detected": false,
                 "result": "clean site",
                 "detail": "http://www.malwaredomainlist.com/mdl.php?search=helenphilwarnes.com"
              },
              "ZeusTracker":       {
                 "detected": false,
                 "result": "clean site",
                 "detail": "https://zeustracker.abuse.ch/monitor.php?host=helenphilwarnes.com"
              },
              "zvelo":       {
                 "detected": false,
                 "result": "clean site"
              },
              "Google Safebrowsing":       {
                 "detected": true,
                 "result": "phishing site"
              },
              "FraudScore":       {
                 "detected": false,
                 "result": "clean site"
              },
              "Kaspersky":       {
                 "detected": true,
                 "result": "phishing site"
              },
              "BitDefender":       {
                 "detected": true,
                 "result": "malware site"
              },
              "Opera":       {
                 "detected": true,
                 "result": "malicious site"
              },
              "Certly":       {
                 "detected": false,
                 "result": "clean site"
              },
              "G-Data":       {
                 "detected": true,
                 "result": "phishing site"
              },
              "C-SIRT":       {
                 "detected": false,
                 "result": "clean site"
              },
              "CyberCrime":       {
                 "detected": false,
                 "result": "clean site"
              },
              "Websense ThreatSeeker":       {
                 "detected": false,
                 "result": "clean site"
              },
              "MalwarePatrol":       {
                 "detected": false,
                 "result": "clean site"
              },
              "Webutation":       {
                 "detected": false,
                 "result": "clean site"
              },
              "Trustwave":       {
                 "detected": true,
                 "result": "malicious site"
              },
              "Web Security Guard":       {
                 "detected": false,
                 "result": "clean site"
              },
              "desenmascara.me":       {
                 "detected": false,
                 "result": "clean site"
              },
              "ADMINUSLabs":       {
                 "detected": false,
                 "result": "clean site"
              },
              "Malwarebytes hpHosts":       {
                 "detected": false,
                 "result": "clean site"
              },
              "Dr.Web":       {
                 "detected": false,
                 "result": "clean site"
              },
              "AlienVault":       {
                 "detected": false,
                 "result": "clean site"
              },
              "Emsisoft":       {
                 "detected": true,
                 "result": "phishing site"
              },
              "Malc0de Database":       {
                 "detected": false,
                 "result": "clean site",
                 "detail": "http://malc0de.com/database/index.php?search=helenphilwarnes.com"
              },
              "malwares.com URL checker":       {
                 "detected": false,
                 "result": "clean site"
              },
              "Phishtank":       {
                 "detected": true,
                 "result": "phishing site"
              },
              "Malwared":       {
                 "detected": false,
                 "result": "clean site"
              },
              "Avira":       {
                 "detected": true,
                 "result": "phishing site"
              },
              "StopBadware":       {
                 "detected": false,
                 "result": "unrated site"
              },
              "Antiy-AVL":       {
                 "detected": false,
                 "result": "clean site"
              },
              "SCUMWARE.org":       {
                 "detected": true,
                 "result": "malware site"
              },
              "FraudSense":       {
                 "detected": false,
                 "result": "clean site"
              },
              "Comodo Site Inspector":       {
                 "detected": false,
                 "result": "clean site"
              },
              "Malekal":       {
                 "detected": false,
                 "result": "clean site"
              },
              "ESET":       {
                 "detected": true,
                 "result": "phishing site"
              },
              "Sophos":       {
                 "detected": true,
                 "result": "malicious site"
              },
              "Yandex Safebrowsing":       {
                 "detected": false,
                 "result": "clean site",
                 "detail": "http://yandex.com/infected?l10n=en&url=http://helenphilwarnes.com/ymal/image.htm"
              },
              "Spam404":       {
                 "detected": false,
                 "result": "clean site"
              },
              "Nucleon":       {
                 "detected": false,
                 "result": "clean site"
              },
              "Malware Domain Blocklist":       {
                 "detected": false,
                 "result": "clean site"
              },
              "Blueliv":       {
                 "detected": false,
                 "result": "clean site"
              },
              "Netcraft":       {
                 "detected": true,
                 "result": "malicious site"
              },
              "AutoShun":       {
                 "detected": false,
                 "result": "unrated site"
              },
              "ThreatHive":       {
                 "detected": false,
                 "result": "clean site"
              },
              "ParetoLogic":       {
                 "detected": false,
                 "result": "clean site"
              },
              "Tencent":       {
                 "detected": false,
                 "result": "clean site"
              },
              "URLQuery":       {
                 "detected": false,
                 "result": "unrated site"
              },
              "Sucuri SiteCheck":       {
                 "detected": false,
                 "result": "clean site"
              },
              "Fortinet":       {
                 "detected": true,
                 "result": "phishing site"
              },
              "ZeroCERT":       {
                 "detected": false,
                 "result": "clean site"
              },
              "Baidu-International":       {
                 "detected": false,
                 "result": "clean site"
              },
              "securolytics":       {
                 "detected": false,
                 "result": "clean site"
              }
           }
        };


scans is another object and you're trying to reference an index. So when you do scans[0] - it's actually looking for the key "0" inside of scans, which doesn't exist. Use a key:

jsonobj.scans["VX Vault"].result

Dont know the keys? Then iterate with a for in loop:

for (var key in jsonobj.scans) {
    console.log(jsonobj.scans[key]);
}