В интернете ничего толкового найти не могу
const obj1 = {
foo: {
bar: {
value: 'final'
}
}
};
function getDeepKeys(obj) {
let keys = [];
for(const key in obj) {
keys.push(key);
if(typeof obj[key] === "object") {
const subkeys = getDeepKeys(obj[key]);
keys = keys.concat(subkeys.map(subkey => `${key}.${subkey}`));
}
}
return keys;
}
console.log(getDeepKeys(obj1)); // ["foo", "foo.bar", "foo.bar.value"]
const obj = {
param1: "1",
param2: "string",
param3: "false"
};
function convertType(prop) {
try {
return JSON.parse(prop);
} catch (e) {
if (e.name === 'SyntaxError') {
return prop;
}
throw e;
}
}
Object.entries(obj).forEach(([key, value]) => {
obj[key] = convertType(value);
});
console.log(obj); // {param1: 1, param2: "string", param3: false}