json data default

Solutions on MaxInterview for json data default by the best coders in the world

showing results for - "json data default"
Camilla
15 Jun 2016
1import json
2
3studentJson ="""{
4   "id": 1,
5   "name": "john wick",
6   "class": null,
7   "percentage": 75,
8   "email": "jhon@pynative.com"
9}"""
10
11student = json.loads(studentJson)
12if not (student.get('subject') is None):
13    print("value is present for given JSON key")
14    print(student.get('subject'))
15else:
16    print("using a default value for a given key")
17    print(student.get('subject', 'Science'))