How to return a json object from a Python function?



We return a json object from a python function as follows using given python dictionary.

Example

import json
a = {'name':'Sarah', 'age': 24, 'isEmployed': True }
# a python dictionary
def retjson():
python2json = json.dumps(a)
print python2json
retjson()

Output

{"age": 24, "isEmployed": true, "name": "Sarah"}

Advertisements