I have a JSON object in which I want to remove the null key with the value that is my JSON. Please give me a solution how can I remove the null attribute with key and value from the object and can get without null keys data
UPDATE:
if request.method == 'POST':
all_products = request.data['products']
db = CategoriesActiveORM.get_connection()
keywords = db.table('categories'). \
select('products', db.raw('count(*) as total')). \
where_not_null('products'). \
group_by('products'). \
order_by('total', 'desc'). \
limit(4). \
get()
total = keywords.sum('total')
industries = {}
for key in keywords:
industries[key['products']] = round(int(key['total']) / total * 100, 2)
print('industries', industries)
industries = industries.pop("null", None)
print('industries', industries)
industries.pop("null", None)
rint('industries', industries)
return JsonResponse(industries)
Print 1:
{
"null": 87.37,
" Product1": 4.95,
" Product2": 4.44,
" Product3": 3.24
}
Print 2:
None
Print 3:
{
"null": 87.37,
" Product1": 4.95,
" Product2": 4.44,
" Product3": 3.24
}