Can't read from mysql json data in python

Question:

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:

{
    "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

Asked By: kaann.gunerr

||

Answers:

You need to parse the data with json,

import json

data = json.loads(kullanici['trendyol_api_bilgileri'])
print(data['entegrasyon_durumu'])
Answered By: Rahul K P
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.