I have a json and I'd like to get only specific values into a list. I can do this just fine iterating through, but I'm wondering if there's an easy one-liner list comprehension method to do this. Suppose I have a json:
{
"results": {
"types":
[
{
"ID": 1
"field": [
{
"type": "date",
"field": "PrjDate"
},
{
"type": "date",
"field": "ComplDate"
}
]
}
]
}
}
I'd like to get all of the field values into a single list:
fieldsList = ['PrjDate', 'ComplDate']
I can do this easily with
for types in myjson['results']['types']:
fieldsList = []
for fields in types['field']:
fieldsList.append(fields['field'])
But that seems unnecessarily clunky, is there an easy one-liner list comprehension method I can use here?
types: [...]?