I've got json formatted file, 'datastores.json' that looks like this:
{
"{'ESXi_Host': 'elvis.lab.vsphere.com'}": {
"elvis.data": {
"capacity": 293131517952,
"uuid": "57431578-630f1322-7bf2-00212883a5b0",
"vmfs_version": "5.60",
"ssd": false,
"extents": [
"mpx.vmhba1:C0:T1:L0"
],
"local": true
I am running the following code on it:
import json
with open("C:\PyVmomi_out\\datastores.json") as json_file:
datastores = json.loads(json_file.read())
for dstor in datastores:
esx_host = dstor['ESXi_Host']
datastore = dstor['datastore']
I get the following error:
TypeError: string indices must be integers
On this line:
esx_host = dstor['ESXi_Host']
I understand that it is expecting an integer. From the reading I had been doing I though if I subbed in
'json.loads'
instead of
'json.load'
and also subbed in
'(json_file.read())'
instead of
'(json_file)'
then it would read the file in as string and allow string parsing instead of integers. Why didn't this work?