I have to fetch output from postgres db and send as output as JSON when a request is made from Postman My code is
import psycopg2
conn = psycopg2.connect(host="localhost", port="5000", dbname="stores", password="*****", user="postgres")
cursor = conn.cursor()
def check():
db = conn.cursor()
db.execute("select * from store1 as name;")
dbop = db.fetchall()
jop = dict(dbop)
return jop
print(check())
My DB structure:
name | price
--------+-------
chair | 10.12
and the output of above python code is:
{'chair': 10.12}
But i need output as,
{
"name" : "chair",
"price" : 10.12
}