I have the json file and its content is like in the below. I have a code for read and parse it. You can see my code in the below.
"['[{\"Manufacturer\": \"VMware, Inc.\", \"Model\": \"VMware7,1\", \"Name\": \"DC01\"}]', '[{\"Index\": \"1\", \"IPAddress\": [\"192.168.1.240,fe80::350e:d28d:14a5:5cbb\"]}]'
my code
with open('data2.json', 'w') as jsonFile:
json.dump(str(output_array), jsonFile)
jsonFile.close()
mySql_insert_query = """INSERT INTO wmi_inventory (wmi_data, date)
VALUES (%s, %s) """
now = datetime.now()
dt_string = now.strftime("%Y-%m-%d-%H:%M:%S")
record = (data, dt_string)
cursor.execute(mySql_insert_query, record)
connection.commit()
with open('data2.json','r') as lst:
data=lst.read()
d = json.loads(json.dumps(data))
print(d["Name"])
When i run my code, im getting this error. How can i solve this?
Traceback (most recent call last):
File "wmi_deneme.py", line 121, in <module>
print(d["Name"])
TypeError: string indices must be integers
I have 3 outputs like :
[{'Manufacturer': 'VMware, Inc.', 'Model': 'VMware7,1', 'Name': 'DC01'}]
[{'Index': '1', 'IPAddress': ['192.168.1.240,fe80::350e:d28d:14a5:5cbb']}]
[{'Name': 'DC01', 'UserName': None}]
I tried to get them all in an array and this is the result. So this is my output array.
[[{'Manufacturer': 'VMware, Inc.', 'Model': 'VMware7,1', 'Name': 'DC01'}], [{'Index': '1', 'IPAddress': ['192.168.1.240,fe80::350e:d28d:14a5:5cbb']}], [{'Name': 'DC01', 'UserName': None}]]
I want to reach this values Name Manucaturer Username.
i'm stuck here