javascript - How to get only particular key value pair from json data and store in variable in node js -


i have sample json data,which need add in different collections in mongodb.but dont want whole json data.for example,

jsondata=   {"widget": { "debug": "on", "window": {     "title": "sample konfabulator widget",     "name": "main_window",     "width": 500,     "height": 500 }, "image": {      "src": "images/sun.png",     "name": "sun1",     "hoffset": 250,  }, "text": {     "data": "click here",     "size": 36,     "style": "bold",  }} 

in json want window key in 1 collection,simillarly image key in mongo collection. thinking if can save key value pair in 1 variable,then can add variable in collection.for trying each

var jsondat=json.parse(jsondata); for(var exkey in jsondat) {  console.log("entering");  var b=stringdata[exkey].image;   console.log(b); }        

but unable image key data.is right approach this?can me out in this. expected result be: in 1 variable,the value of window key should saved in json format. simillarly image , text keyvalues in variables.

thanks.

why aren't fetching window , image object key like:

var window= jsondata.widget.window; var image = jsondata.widget.image; 

and save them in mongo db

db.window.insert(window) db.image.insert(image) 

tell me if understand right.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -