I have a JSON of the below format in a textarea
{
"name": "Stub",
"request": {
"method": "GET",
"url": "/thing/1",
"queryParameters": {
"Accept": {
"equalTo": "xm1"
}
}
},
"response": {
"status": 200
}
}
And as a part of my requirement I have a text box which has a onkeyup event which has to invoke a javascript function to replace the key param under queryParameters with the value that is newly typed in the text box
<input type="text" onkeyup="javascript:setFontText4(this.value);" size="10" id="Name1" name="Name1" value="Accept">
For example, if a user types "Change" in the textbox the newly constructed JSON should be as below
{
"name": "Stub",
"request": {
"method": "GET",
"url": "/thing/1",
"queryParameters": {
"Change": {
"equalTo": "xm1"
}
}
},
"response": {
"status": 200
}
}
I wouldn't be sure if mutating would help here cause the "key" isn't static
I came across this nice example but I'm skeptical again cause the key isn't static
function setFontText4(text) {
obj = { name: 'Bobo' }
obj.somethingElse = obj.name
delete obj.name
document.getElementById("urls").innerHTML = JSON.stringify(obj, undefined, 4);
}