/**
need a function to give me results like this.
i have it as far as the structure, but the data is not going to the right place
{
"workspaces": {
"999": {
"views": {
"222": {
"urn:adsk-plm:tenant-workspace-view-field:VRDEVINDMACHINEFESTIVA-20-0-DESCRIPTOR": {
"columnWidth": 1347
},
"urn:adsk-plm:tenant-workspace-view-field:VRDEVINDMACHINEFESTIVA-20-0-WF_CURRENT_STATE": {
"columnWidth": 240
}
},
"2223": {
"urn:adsk-plm:tenant-workspace-view-field:VRDEVINDMACHINEFESTIVA-20-0-DESCRIPTOR": {
"columnWidth": 1347
},
"urn:adsk-plm:tenant-workspace-view-field:VRDEVINDMACHINEFESTIVA-20-0-WF_CURRENT_STATE": {
"columnWidth": 240
}
}
}
}
}
}
*/
function parsePathToJson(path, data) {
let eachPath = path.split('/');
let output = {[eachPath[0]]:{}};
let currentDir = output[eachPath[0]];
for (let i = 1; i < eachPath.length; i++) {
if(i == eachPath.length-1) {
currentDir[eachPath[i]] = data || {}
}
else
currentDir[eachPath[i]] = currentDir[eachPath[i]] || {};
currentDir = currentDir[eachPath[i]]
}
return output;
}
function getValueAtPath(path, storedData) {
let eachPath = path.split('/');
let results = {};
if(!storedData) {
return {[eachPath[eachPath.length-1]]:{}}
}
//traverses each path untill a key does not exist or there are no more keys in the path
for (let i = 0; i < eachPath.length; i++) {
if(storedData[eachPath[i]]) {
//result exists
results = {[eachPath[i]]:storedData[eachPath[i]]};
} else {
//no results
results = {[eachPath[i]]:{}}
break;
}
}
return results;
}
var data = {
"urn:adsk-plm:tenant-workspace-view-field:VRDEVINDMACHINEFESTIVA-20-0-DESCRIPTOR": {
"columnWidth": 1347
},
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.