Check if key exists and iterate the JSON array using Python

前端 未结 7 459
南旧
南旧 2020-12-02 06:28

I have a bunch of JSON data from Facebook posts like the one below:

{\"from\": {\"id\": \"8\", \"name\": \"Mary Pinter\"}, \"message\": \"How ARE you?\", \"c         


        
相关标签:
7条回答
  • 2020-12-02 07:27

    I wrote a tiny function for this purpose. Feel free to repurpose,

    def is_json_key_present(json, key):
        try:
            buf = json[key]
        except KeyError:
            return False
    
        return True
    
    0 讨论(0)
提交回复
热议问题