Hi All,
Any thoughts on how to get a proper JSON object out from below? I am getting JS object just fine but for some reason using JSON.stringify is encoding the double qoutes.
lv_json = {"profile.login":"Valian@mail.com", "profile.OrgManPositionLevel":"PRODUCT", "profile.OrgManPositionCode":"ED100000R", "profile.email":"Valian@mail.com", "profile.OrgManSubteamName":"PRODUCT"}
//Object is ready, now pass it to unflatten FM
//lr_result = unflatten(lv_flattend_json);
lr_result = unflatten(lv_json);
//lr_json1 = JSON.parse(lr_result);
//lr_string = JSON.parse(JSON.stringify(lr_result));
lr_string = JSON.stringify(lr_result);
lr_string = JSON.stringify(lr_string).replace(/\"/gi, "");
//console.log(Array.isArray(lr_result.profile.ad_site_permissions));
console.log(lr_result);
//console.log(lr_json1);
console.log(lr_string);
function unflatten(data) {
//console.log("inside the unflatten........");
"use strict";
if (Object(data) !== data || Array.isArray(data))
return data;
var regex = /\.?([^.\[\]]+)|\[(\d+)\]/g,
resultholder = {};
for (var p in data) {
var cur = resultholder,
prop = "",
m;
while (m = regex.exec(p)) {
cur = cur[prop] || (cur[prop] = (m[2] ? [] : {}));
prop = m[2] || m[1];
}
//console.log(prop);
//console.log(data[p]);
cur[prop] = data[p];
}
//console.log("Exiting the unflatten........");
return resultholder[""] || resultholder;
}
Current Output :
{
profile: {
email: "Valian@mail.com",
login: "Valian@mail.com",
OrgManPositionCode: "ED100000R",
OrgManPositionLevel: "PRODUCT",
OrgManSubteamName: "PRODUCT"
}
}
"\"{\\"profile\\":{\\"login\\":\\"Valian@mail.com\\",\\"OrgManPositionLevel\\":\\"PRODUCT\\",\\"OrgManPositionCode\\":\\"ED100000R\\",\\"email\\":\\"Valian@mail.com\\",\\"OrgManSubteamName\\":\\"PRODUCT\\"}}\""
Output needed:
{
"profile": {
"email": "Valian@mail.com",
"login": "Valian@mail.com",
"OrgManPositionCode": "ED100000R",
"OrgManPositionLevel": "PRODUCT",
"OrgManSubteamName": "PRODUCT"
}
}