我有一个我正在用 Python 清理的 JSON 数组。我想删除该imageData
属性:
数据.json
[{"title": "foo", "imageData": "xyz123"},
{"title": "bar", "imageData": "abc123"},
{"title": "baz", "imageData": "def456"}]
我正在设置一个列表理解来删除该属性,但我不确定如何创建关注的变量imageData
:
import json
with open('data.json') as json_data:
data = json.load(json_data)
clean_data = [ item for item in data if not item['imageData'] ]
# Write `clean_data` to new json file
当我print
列表理解时,它返回一个空数组。我必须纠正什么才能使其正常工作?