I need get values from key "color" in json using python, only for first level
json dumps:
[{"color": "red", "value": "10"}, {"color": "blue", "value": [{"color": "black", "value": "15"}]}]
I need:
[ 'red', 'blue']
I tried:
my_values = my_json_a.get('color')
But with error:
Error Contents: 'list' object has no attribute 'get'
Try:
data = [{"color": "red", "value": "10"}, {"color": "blue", "value": [{"color": "black", "value": "15"}]}]
results = [x.get('color', None) for x in data]
print results
Output:
['red', 'blue']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With