Write a program to Check if the key exists or not in JSON
Topic: Write a program to Check if the key exists or not in JSON
Solution
import json studentJson ="""{ "id": 1, "name": "Piyush Jain", "class": null, "percentage": 35, "email": "piyushjain220@gmail.com" }""" print("Checking if percentage key exists in JSON") student = json.loads(studentJson) if "percentage" in student: print("Key exist in JSON data") print(student["name"], "marks is: ", student["percentage"]) else: print("Key doesn't exist in JSON data")
List all Python Programs