Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can't read from mysql json data in python

I can’t get variables in json format from mysql.

My code:

import mysql_db
import json

# Tüm kullanıcılar çekildi ve  kullanıcı sayısı kadar döndürüldü
tum_kullanicilar = mysql_db.mysql_get_all("select * from users")
for kullanici in tum_kullanicilar:
    print(kullanici['trendyol_api_bilgileri'])

Output:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{
    "api_key": "xxx",
    "api_secret": "xxx",
    "merchant_id": "xxx",
    "default_kargo_id": "2",
    "default_kargo_adi": "MNG Kargo",
    "entegrasyon_durumu": 1,
    "defaultinvoiceAddressId": 659331,
    "defaultshipmentAddressId": 5785842,
    "defaultreturningAddressId": 659321
}

I’m trying to do:

kullanici['trendyol_api_bilgileri']['entegrasyon_durumu']

TypeError: string indices must be integers

>Solution :

You need to parse the data with json,

import json

data = json.loads(kullanici['trendyol_api_bilgileri'])
print(data['entegrasyon_durumu'])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading