I have this JSON object below;
[ { XXX: "2", YYY: "3", ZZZ: "4" }, { XXX: "5", YYY: "6", ZZZ: "7" }, { XXX: "1", YYY: "2", ZZZ: "3" } ]
I want to remove the YYY key-value from the json object such that the new json object will look like this;
[ { XXX: "2", ZZZ: "4" }, { XXX: "5", ZZZ: "7" }, { XXX: "1", ZZZ: "3" } ]
I tried delete jsonObject['YYY']
but this is not correct. How can this be done in javascript? Thank you.
JsonObject::remove() removes a key-value pair from the object pointed by the JsonObject . If the JsonObject is null, this function does nothing.
To remove JSON object key and value with JavaScript, we use the delete operator.
To remove JSON element, use the delete keyword in JavaScript.
To delete a JSON object from a list: Parse the JSON object into a Python list of dictionaries. Use the enumerate() function to iterate over the iterate over the list. Check if each dictionary is the one you want to remove and use the pop() method to remove the matching dict.
What you call your "JSON Object" is really a JSON Array of Objects. You have to iterate over each and delete each member individually:
for(var i = 0; i < jsonArr.length; i++) { delete jsonArr[i]['YYY']; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With