I would like to access all the keys including within lists in a JSON document and modify them.
I have the following code, but this just prints the top level keys:
#!/usr/bin/env python3
import json
file = 'example.json'
f = open(file)
data = json.load(f)
for key, value in data.items():
print(key)
Thus, for the JSON document:
{
"a":1,
"b":2,
"c":[
{
"d":4,
"e":5,
"f":{
"g":6
}
}
]
}
I just get the output:
a
b
c
whereas I want to access and amend all the keys, namely:
a
b
c
d
e
f
g
Note that c is a list, which hides d e f g.