Shanthi
Shanthi

Reputation: 716

How to get key and value separately from json in node js

I have a json like this

{"Beauty_Personal_Care": {
"listingVersions": {
  "v1": {
    "get": "http://affiliate-feeds.snapdeal.com/feed/api/category/v1:586:680986904635?expiresAt=1455143400082&signature=gtvuofdhkeqxipadfzyf"
  }
 }
},
"Eyewear": {
"listingVersions": {
  "v1": {
    "get": "http://affiliate-feeds.snapdeal.com/feed/api/category/v1:473:630636448881?expiresAt=1455143400082&signature=gtvuofdhkeqxipadfzyf"
   }
  }
 }
}

I want to get key value and objects of key value separately in node js backend.

Expected result:

name="Beauty_Personal_Care";

url="http://affiliate-feeds.snapdeal.com/feed/api/category/v1:586:680986904635?expiresAt=1455143400082&signature=gtvuofdhkeqxipadfzyf";

Upvotes: 1

Views: 722

Answers (1)

user1695032
user1695032

Reputation: 1142

var json = {}; // your json
var result = [];
Object.keys(json).forEach(function (name) {
    var data = {
        name: name
    };

    data.url = json[name].listingVersions.v1.get;
    result.push(data);
});

console.log(result);

Upvotes: 1

Related Questions