-3
import json

x = ''' {
   "result":{
      "firstList":[
         {
            "username":"a@gmail.com",
            "password":"123"
         }
      ]
   },
   "size":1,
   "took":436
} ''' # The Json

seloco = json.loads(x)
print(seloco) # Print Json

How can I print username and password?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
K.C
  • 1
  • 1

2 Answers2

0

Like that :

>>> print(seloco['result']['firstList'][0]['username'])
a@gmail.com
>>> print(seloco['result']['firstList'][0]['password'])
123
0
import json

x = ''' {
   "result":{
      "firstList":[
         {
            "username":"a@gmail.com",
            "password":"123"
         }
      ]
   },
   "size":1,
   "took":436
} ''' # The Json

seloco = json.loads(x)
print(seloco) # Print Json
user = seloco["result"]["firstList"][0]
username = user["username"]
password = user["password"]
print(username)
print(password)
ONMNZ
  • 322
  • 3
  • 8