Python Forum
converting mysqli to json - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: converting mysqli to json (/thread-11326.html)



converting mysqli to json - ameliabob - Jul-03-2018

I downloaded a data base table and asked that it be converted into json. What I got was:
[{"rowId": 21,"nature": "O","symbol": "TAL","qty": 10,"daysHeld": 0,"source": "Momentum","dayEntered": "2018-01-16","pl": -40}, {"rowId": 22,"nature": "O","symbol": "SGMO","qty": 5,"daysHeld": 35,"source": "Lightning Trend","dayEntered": "2018-02-06","pl": 2300}]

When I bring it into Python/json is comes in as a list. How do I get it into a dictionary?

Also what is the statement to modify i.e. the pl 2300 to 230?

Thanx


RE: converting mysqli to json - Larz60+ - Jul-03-2018

you've got a list with one item that is a dictionary
you didn't supply much information about your code, nor a code example, so
lets assume the name of your converted JSON list is mylist, then
if you try:
>>> type(mylist)
<class 'list'>
>>> type(mylist[0])
<class 'dict'>
>>> mydict = mylist[0]
>>> type(mydict)
<class 'dict'>
>>> print(mydict)
{'rowId': 21, 'nature': 'O', 'symbol': 'TAL', 'qty': 10, 'daysHeld': 0, 'source': 'Momentum', 'dayEntered': '2018-01-16', 'pl': -40} >>>