Here is the JSON object that I am currently handling:
{
"name": "John Smith",
"age": 32,
"employed": true,
"address": {
"street": "701 First Ave.",
"city": "Sunnyvale, CA 95125",
"country": "United States"
},
"children": [
{
"name": "Richard",
"age": 7
},
{
"name": "Susan",
"age": 4
},
{
"name": "James",
"age": 3
}
]
}
Now, I aim to include a new key-value pair like this:
"collegeId": {
"eventno": "6062",
"eventdesc": "abc"
};
I attempted to combine them using concat but it resulted in || symbol and I couldn't iterate. Splitting only removes commas.
concattedjson = JSON.stringify(JSON.parse(json1).concat(JSON.parse(json2)));
Can you guide me on how to add a new key-value pair to an existing JSON object in JavaScript?