Q:

Python JSON add Key-Value pair

I'm trying to add key value pairs into the existing JSON file. I am able to concatenate to the parent label, How to add value to the child items?
JSON file:
{
  "students": [
    {
      "name": "Hendrick"
    },
    {
      "name": "Mikey"
    }
  ]
}

Code:
import json

with open("input.json") as json_file:
    json_decoded = json.load(json_file)

json_decoded['country'] = 'UK'

with open("output.json", 'w') as json_file:
    for d in json_decoded[students]:
        json.dump(json_decoded, json_file)

Expected Results:
{
  "students": [
    {
      "name": "Hendrick",
      "country": "UK"
    },
    {
      "name": "Mikey",
      "country": "UK"
    }
  ]
}

A:

You can do the following in order to manipulate the dict the way you want:
for s in json_decoded['students']:
    s['country'] = 'UK'

json_decoded['students'] is a list of dictionaries that you can simply iterate and update in a loop. Now you can dump the entire object:
with open("output.json", 'w') as json_file:
    json.dump(json_decoded, json_file)

