Removing JSON property in array of objects

前端 未结 4 1298
鱼传尺愫
鱼传尺愫 2020-12-09 09:26

I have a JSON array that I\'m cleaning up in Python. I want to remove the imageData property:

data.json

[{\"title\": \"         


        
4条回答
  •  爱一瞬间的悲伤
    2020-12-09 09:58

    If not all the elements have an imageData key, then using del will cause an KeyError exception. You could guard against that by using pop with a default:

    for item in data: 
        item.pop('image', None)
    

提交回复
热议问题