เราคืนค่าอ็อบเจ็กต์ json จากฟังก์ชัน python ดังนี้โดยใช้พจนานุกรม python ที่กำหนด
ตัวอย่าง
import json
a = {'name':'Sarah', 'age': 24, 'isEmployed': True }
# a python dictionary
def retjson():
python2json = json.dumps(a)
print python2json
retjson() ผลลัพธ์
{"age": 24, "isEmployed": true, "name": "Sarah"}