I have the following JSON string:
jsonString = {'result': {'animals': {'Dogs': True, 'Cats': True}}
So in Python I know I can do:
animals= jsonString['result']['animals']
To get the value of 'Dogs' or 'Cats'. And:
animals= jsonString['result']['animals']['Dogs']
To get the value of 'Dogs' or 'Cats'.
However, when I try print (jsonString['result']['animals']) I get:
{'Dogs': True, 'Cats': True}
Question
How do I get the all the animals, without values, dynamically?
Thanks.
['Dogs', 'Cats']?jsonString['result']['cats'].keys()?dictand this has nothing to do with json, and I think you want.keys()to get the keys of the dict, however the print statement you provided is not a valid python commandlist(jsonString["result"]["cats"].keys())but accept Tadhg McDonald-Jensen's answer; it's more informative.