I need help adding a new key to a JSON array by searching for a specific key value.
For example JSON:-
[
{
"$id": "2025",
"ID": 41,
"Name": "APPLE"
},
{
"$id": "2026",
"ID": 45,
"Name": "MANGO"
},
{
"$id": "2027",
"ID": 48,
"Name": "GUAVA"
}
]
Let's say I want to add a new key pair like "Price": 50
after "Name": "MANGO"
or by finding the ID ID: 45
. The expected updated JSON should look like this:
[
{
"$id": "2025",
"ID": 41,
"Name": "APPLE"
},
{
"$id": "2026",
"ID": 45,
"Name": "MANGO",
"Price": 50
},
{
"$id": "2027",
"ID": 48,
"Name": "GUAVA"
}
]
The new key-value pair should be added to the object related to the matched search key.
I'm having trouble finding a function that addresses this issue. Can anyone provide guidance?