I have a pretty weird JSON string from which I need specific values saved in a .txt file.
The string looks like this:
{"available":[{"place":"abc","stock":3},{"place":"abcd","stock":5}]}
So I need to extract the "place" and "stock" into a list. So the result should look like this:
abc 3
abcd 5
I tried it with:
with open("available.txt", "w") as f:
for i in list['available']:
f.write(I['place'] + ['stock'] + '\n')
But it won't work. I think its because the "stock" value does not have any "". Is it possible to do what I want with Python?
str(i['stock'])?stock. you're forgetting to look up the key ini["stock"]Iis undefined first.