I've had trouble printing the values of the key "uuid". The "uuid" key shows up multiple times throughout the file whilst other keys that are only present in the file once have no trouble being printed. So I'm wondering is it possible to do what I want it to do? The error I'm getting is a KeyError: 'uuid' for your information.
path = os.path.join(startn, listn + endn)
with open(path, encoding='utf-8') as json_file:
auction = json.load(json_file)
print("Type:", type(auction))
print("\nAuction:", auction['uuid'])
Also the file data looks like this
{"uuid":"36ff18f6e56d49b18c55cd06df3dfce8","auctioneer":"7c1251d409524cfd96b68da183698676","profile_id":"b7c111408b7c4d57a0665edda28c3b77"} {"uuid":"754c3f2a25d949d1907f9c29f761b636","auctioneer":"f281bf681baa4cfea8a798cbe76c15f3","profile_id":"f281bf681baa4cfea8a798cbe76c15f3"}
etc...
Given that you haven't given us the full json but rather a messed up one
{"uuid":"36ff18f6e56d49b18c55cd06df3dfce8","auctioneer":"7c1251d409524cfd96b68da183698676","profile_id":"b7c111408b7c4d57a0665edda28c3b77"} {"uuid":"754c3f2a25d949d1907f9c29f761b636","auctioneer":"f281bf681baa4cfea8a798cbe76c15f3","profile_id":"f281bf681baa4cfea8a798cbe76c15f3"}
I assume that the actual json is something like this
[
{
"uuid": "36ff18f6e56d49b18c55cd06df3dfce8",
"auctioneer": "7c1251d409524cfd96b68da183698676",
"profile_id": "b7c111408b7c4d57a0665edda28c3b77"
},
{
"uuid": "754c3f2a25d949d1907f9c29f761b636",
"auctioneer": "f281bf681baa4cfea8a798cbe76c15f3",
"profile_id": "f281bf681baa4cfea8a798cbe76c15f3"
}
]
This is an array of json. What python is returning is an array, which is not accessed by key. You need to iterate the array like so
with open(path, encoding='utf-8') as json_file:
// Changed the return as plural because this is an array
auctions = json.load(json_file)
// Iterate through your array
for auction in auctions:
print("Type:", type(auction))
print("\nAuction:", auction['uuid'])