I need to modify my JSON Object by add/remove Json element. Here is my JSON Object,
var candidate = {
"name":"lokesh",
"age":26,
"skills":[
"Java",
"Node Js",
"Javascript"
]
};
I need to remove the element "skills" and output should be like,
{
"name":"lokesh",
"age":26
}
And I again I need to add the element "skills" as string and the output should be like,
{
"name":"lokesh",
"age":26,
"skills":"javascript"
}
Please help,
Thanks in advance.
You can remove an element from the JSONArray object using the remove() method. This method accepts an integer and removes the element in that particular index.
The toJSON() method returns a string representation of the Date object.
To remove JSON object key and value with JavaScript, we use the delete operator.
String jsonFormattedString = jsonStr. replaceAll("\\", "");
Other ways it can be achieved.
For Adding:
candidate["skills"] = "javascript";
For Deleting:
var skill = "javascript";
delete candidate[skill];
or
delete candidate.skills;
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