I have a JSON that I am trying to change a value in
{
string: "Hi",
number: 0,
boolean: false,
object: {
subString: "Hello",
subNumber: 1,
subBoolean: true,
subObject: {
subSubString: "Hello World"
},
subArray: ["-1", "-2", "-3"]
},
array: ["1", "2", "3"]
}
I have a piece of code that takes in a string with a JSON key and a new value (Eg. "object.subNumber", 5) and I am trying to get it to set the value of the subNumber value in the object ({ ... object: { ... subNumber: 5 ... } ... }
), but I can't get it to work.
Here is what I have tried
var keys = args[0].split(".")
var value = args[1]
var configKey = config
keys.forEach(key => { configKey = configKey[key] })
configKey = value
which doesn't work. Is there some way to do this?