sachin yadav
sachin yadav

Reputation: 367

how can i access the value of each data from this json?

{
    "sachin.company": {
        "classkey": "dotcompany",
        "status": "available"
    },
    "sachin.com": {
        "classkey": "domcno",
        "status": "regthroughothers"
    },
    "sachin.co.in": {
        "classkey": "thirdleveldotin",
        "status": "regthroughothers"
    },
   "sachin.org": {
        "classkey": "domorg",
        "status": "regthroughothers"
    },
    "sachin.guru": {
        "classkey": "dotguru",
        "status": "available"
    },
    "sachin.sexy": {
        "classkey": "dotsexy",
        "status": "available"
    },
    "sachin.nettlds=asia": {
        "status": "unknown"
    }
}

I want to access the classKey and status from this object. how can I access for each of keys value? I tried this var keys = Object.keys(response); but this only create the array like ["sachin.company", "sachin.in", "sachin.community", "sachin.com", "sachin.computer", "sachin.co.in", "sachin.org", "sachin.compare", "sachin.net"]

Upvotes: 0

Views: 60

Answers (2)

Viran Malaka
Viran Malaka

Reputation: 427

If you want to get all defined values
do as follows,

var allValues = [];
var keys = Object.keys(parsedJson);
Object.values(parsedJson).forEach(function(x) {
    Object.values(x).forEach(function(y){
       this.allValues.push(y);
    }, this);
}, this);

allValues will give you what you want.
Thanks.

Upvotes: 0

skiilaa
skiilaa

Reputation: 1282

Object.keys(parsedJson).forEach(function(value){
    var classKey = parsedJson[value].classKey;
    var status = parsedJson[value].status;
    //do whatever you want with them
});

Upvotes: 1

Related Questions