Mar-10-2022, 08:34 AM
Hi. 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\"]}]'
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\"]}]'
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