[
{
"A":"C:/user/...",
"B":2
},
{
"A":"C:/abd/...",
"B"4
}
]
When the above file is referred to as example.json
, I would like to make a list by extracting only the values for key'A'
. How can I code in this case? (For example, I didn't write down the path name correctly, but the actual file contains all the data values correctly.)
with open('example.json') as make_json:
json_data = json.load(make_json)
I read it like this
A_value = json_data["A"]
causes a TypeError that the index in the list must be integrers, not str.
I'd appreciate your help.
python json
A_values = [ e["A"] for e in json_data ]
deusyo.
© 2025 OneMinuteCode. All rights reserved.