How to return a json object from a Python function?

PythonServer Side ProgrammingProgramming

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"}
raja
Published on 07-Dec-2017 17:52:25
Advertisements