My JSON file is,
{
"student1": {
"Name": "Caroline",
"Age": "24",
"email": "Caroline123@gmail.com",
"Phone": "1234567890",
"Blood group": "O+ve"
}
}
My desired output is,
{
"student1": {
"Name": "Caroline",
"Age": "24",
"email": "Caroline123@gmail.com",
"Phone1": "1234567890",
"Phone2": "1267345980",
"Phone3": "9865432130",
"Blood group": "O+ve"
}
}
The new key-value pairs Phone1, Phone2 and Phone3 , whose values are stored in the array called VALUES, needs to be added in the place of the key Phone
m=1
for i in ${VALUES[@]}
do
jq --arg newval "$i" '.student1 += { VALUES$m: $newval }' <<<"$filepath"
let "m += 1"
done
Above is my code, But it's not working! Can anyone please help me to get the desired output!