I would like to take some JSON, convert it into a dictionary and then change some of the values in that dictionary.
I've tried a few things as shown below but I can't get it to work as intended.
My JSON is as follows:
{
"9":[
{
"09_000":{
"name":"Wyatt Feldt",
"1":"R",
"2":"L",
"w":1,
"h_t":1
}
},
{
"09_001":{
"name":"Clayton Friend",
"1":"R",
"2":"R",
"w":0,
"h_t":0
}
}
],
"10":[
{
"09_000":{
"name":"Wyatt Feldt",
"1":"R",
"2":"L",
"w":1,
"h_t":1
}
},
{
"09_001":{
"name":"Clayton Friend",
"1":"R",
"2":"R",
"w":0,
"h_t":0
}
}
],
"11":[
{
"09_000":{
"name":"Wyatt Feldt",
"1":"R",
"2":"L",
"w":1,
"h_t":1
}
},
{
"09_001":{
"name":"Clayton Friend",
"1":"R",
"2":"R",
"w":0,
"h_t":0
}
}
]
}
And then in Python I have written print(my_data["9"][0])
which returns {'09_000': {'name': 'Wyatt Feldt', '1': 'R', '2': 'L', 'w': 1, 'h_t': 1}}.
However, I just want it to return {'name': 'Wyatt Feldt', '1': 'R', '2': 'L', 'w': 1, 'h_t': 1} because I don't just want to print it, I want to set some of the values e.g. the name. And I know I can do that by doing my_data["9"][0]["09_000"]
but I don't want to use that ID in order to get it (only the outer group, the index and then the key e.g. "name"). Since I'm already returning {'09_000': {'name': 'Wyatt Feldt', '1': 'R', '2': 'L', 'w': 1, 'h_t': 1}} I'm sure there must be a way to just get the nested part ({'name': 'Wyatt Feldt', '1': 'R', '2': 'L', 'w': 1, 'h_t': 1}) so I can change the values.
EDIT: I think it's a different issue. My my_data
variable is already in dictionary format, and this is a special case of indexing.