I have a defaultObject like that:
var default = {
abc: \"123\",
def: \"456\",
ghi: {
jkl: \"789\",
mno: \"012\"
}
};
I found that the easiest way to to this is to use mergeWith() from lodash ( https://lodash.com/docs/4.17.15#mergeWith ) which accepts a customizer function that decides what to do with every property merge. Here is one that is recursive :
const mergeFunction = (objValue, srcValue) => {
if (typeof srcValue === 'object') {
_.mergeWith(objValue, srcValue, mergeFunction)
} else if (objValue) {
return objValue
} else {
return srcValue
}
}