Reputation: 191
I have something like:
sysbus = json.loads(file)
print sysbus
>>> [{u'eth3': u'pci@0000:03:00.1', u'eth2': u'pci@0000:03:00.0', u'eth1': u'pci@0000:06:00.1', u'eth0': u'pci@0000:06:00.0'}]
I would like to convert sysbus into a dictionary.
{'eth3': 'pci@0000:03:00.1', 'eth2': 'pci@0000:03:00.0', 'eth1': 'pci@0000:06:00.1', 'eth0': 'pci@0000:06:00.0'}
What is the cleanest way to convert this?
Upvotes: 0
Views: 1902
Reputation: 55197
It looks like you just want the first item from this list, so get that:
sysbus = json.loads(file)[0]
Do you expect this file
could somehow contain multiple entries in the list? If yes, then you might want to check the length for the list first.
Upvotes: 2