I create a JSON object with the following code
var config = {"config": {
"example": false,
"example2": true,
}
};
I want to conditionally add (or not) some values to the middle of the config object. I tried the following:
var additionalconfig = "";
if(additionalconfig){
additionalConfig = {"additional1":true,
"additional2":2};
}
var config = {"config": {
"example": false,
additionalConfig,
"example2": true,
}
};
I got the extra config added as an extra node (list?) which is not what I want. My expected result is:
"config": {
"example": false,
"additional1":true,
"additional2":2
"example2": true,
}
I tried to remove the node by using additionalconfig[0]
but I got an error Unexpected token [
. Than I tried to add it as a String
additionalConfig = '"additional1":true,
"additional2":2';
But I also got an error. Do you know if its possible to achieve this and if yes how? I need to add the configuration in an exact position, not just merge the two objects