Mar-10-2022, 01:51 PM
(Mar-10-2022, 01:43 PM)snippsat Wrote:(Mar-10-2022, 01:07 PM)ilknurg Wrote: My json is coming me like :lst = [ [{"Manufacturer": "VMware, Inc.", "Model": "VMware7,1", "Name": "DC01"}], [{"Index": "1", "IPAddress": ["192.168.1.240,fe80::350e:d28d:14a5:5cbb"]}], [{"Name": "DC01", "UserName": None}], ]So your data that i just copy before,then withoutlst
copy into JSON Formatter.
It will fix a couple of thing,then usedata.json
.
import json from pprint import pprint with open('data.json', 'r') as myfile: data = json.load(myfile) pprint(data) print(data[0][0].get('Manufacturer'))
Output:[[{'Manufacturer': 'VMware, Inc.', 'Model': 'VMware7,1', 'Name': 'DC01'}], [{'IPAddress': ['192.168.1.240,fe80::350e:d28d:14a5:5cbb'], 'Index': '1'}], [{'Name': 'DC01', 'UserName': 'None'}]] VMware, Inc.
Thank you. It helped me a lot. But i didnt understand the meaning of data[0][0]. It is the first element of data array?
I try to reach Name, I wrote data[0][3] and i get IndexError: list index out of range