How to convert JSON to map using javascript? -


i have convert nested json map using javascript.

json file

{ "centers" : {   "er" : {     "admin":{       "users" : {         "emp1" : {           "password" : "abcdefgh",           "username" : "pankaj-roy"         },         "emp2" : {           "password" : "12345678",           "username" : "niketan-shah"         }       }     }   } } } 

i have create map above json file.

map

key          value centers      er er           admin admin        users users        emp1,emp2 emp1         password,username emp2         password,username 

i think looking for.

function keymap(src, target){    target = target || {};    object.keys(src).foreach(function(propname){       var prop = src[propname];       if(typeof prop == "object"){         target[propname] = object.keys(prop).join(',');         keymap(prop, target);       }    });    return target;  };    var result = keymap({  "centers" : {    "er" : {      "admin":{        "users" : {          "emp1" : {            "password" : "abcdefgh",            "username" : "pankaj-roy"          },          "emp2" : {            "password" : "12345678",            "username" : "niketan-shah"          }        }      }    }  }  });                          console.log(result);


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -