TypeError: Object of type Decimal is not JSON serializable
While I am running in postman api
i get the above error because sales_qty
is decimal , I dont know how to parse decimal
in a for
loop and return it as json
from flask import Flask, jsonify
import decimal,json
result= [('V_M_001', 'KITE', 'Napkin', 1, 2, 12, 0, Decimal('0'), Decimal('0'), Decimal('0'), Decimal('0')),
('V_M_001', 'KITE', 'Napkin', 2, 4, 34, 5, Decimal('1'), Decimal('4'), Decimal('0'), Decimal('0'))]
def fun():
for i in result:
data_all.append({
"machine_name":i.machine_name,
"location":i.location,
"item_name":i.item_name,
"row_no":i.row_no,
"require_minimum_stk_qty":i.require_minimum_stk_qty,
"capacity":i.capacity,
"stock_qty":i.stock_qty,
"sales_qty":i.sales_qty,
"available_qty":i.available_qty,
"sales_day_qty":i.sales_day_qty,
"sales_week_qty":i.sales_week_qty
})
return jsonify(data_all)
fun()
Output:
TypeError: Object of type Decimal is not JSON serializable