I am trying to extract certain positions from AWS pricelist, but I am keeping getting the below error code. Is there an error with JSON structure ?
Traceback (most recent call last):
File "/Python/python2.py", line 5, in <module>
for r in data['SJQU8C5FNVFYMK7X']:
KeyError: 'SJQU8C5FNVFYMK7X
JSON FILE
"SJQU8C5FNVFYMK7X" : {
"sku" : "SJQU8C5FNVFYMK7X",
"productFamily" : "Compute Instance",
"attributes" : {
"servicecode" : "AmazonEC2",
"location" : "Asia Pacific (Singapore)",
"locationType" : "AWS Region",
"instanceType" : "r5n.8xlarge",
"currentGeneration" : "Yes",
"instanceFamily" : "Memory optimized",
"vcpu" : "32",
"physicalProcessor" : "Intel Xeon Platinum 8259 (Cascade Lake)",
"clockSpeed" : "2.5 GHz",
"memory" : "256 GiB",
"storage" : "EBS only",
"networkPerformance" : "25 Gigabit",
"processorArchitecture" : "64-bit",
"tenancy" : "Shared",
"operatingSystem" : "Windows",
"licenseModel" : "No License required",
"usagetype" : "APS1-BoxUsage:r5n.8xlarge",
"operation" : "RunInstances:0102",
"capacitystatus" : "Used",
"dedicatedEbsThroughput" : "5000 Mbps",
"ecu" : "NA",
"enhancedNetworkingSupported" : "No",
"intelAvxAvailable" : "No",
"intelAvx2Available" : "No",
"intelTurboAvailable" : "No",
"normalizationSizeFactor" : "64",
"preInstalledSw" : "SQL Ent",
"servicename" : "Amazon Elastic Compute Cloud"
}
Python code:
import json
with open('index (5).json') as json_file:
data = json.load(json_file)
for r in data['SJQU8C5FNVFYMK7X']:
print (r)
Any ideas what I am doing wrong ?
datavariable, I don't see a problem. I just run your code it worked fine. It printed:sku,productFamilyandattributes. Was that what you wanted to print? If you wanted to print the attributes, you should have useddata['SJQU8C5FNVFYMK7X']['attributes'].