1import json
2
3studentJson ="""{
4 "id": 1,
5 "name": "john wick",
6 "class": 8,
7 "percentage": 75,
8 "email": "jhon@pynative.com"
9}"""
10
11print("Checking if percentage key exists in JSON")
12student = json.loads(studentJson)
13if "percentage" in student:
14 print("Key exist in JSON data")
15 print(student["name"], "marks is: ", student["percentage"])
16else:
17 print("Key doesn't exist in JSON data")
1if 'to' not in data:
2 raise ValueError("No target in given data")
3if 'data' not in data['to']:
4 raise ValueError("No data for target")
1json_string = """{"a": 1, "b": 2, "c": 3}"""
2a_dictionary = json.loads(json_string)
3
4b_in_dict = "b" in a_dictionary