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
Post a Comment