user3188033 user3188033 - 2 months ago 8
JSON Question

how to pass json in python

I am using python and have a json response :

{u'outcomes': [{u'entities': {}, u'confidence': 0.951, u'intent': u'timeanddate', u'_text': u'what is the'}], u'msg_id': u'629bbdbd-788b-4418-a5cf-1f9a7895f490', u'_text': u'what is the'}


I would like to access the information like this or something similar:

COMMANDS["outcomes"]["intent"]


How would I do this.

Thank You

Answer

Pay attention to the hierarchy. You'll notice the dictionary containing the intent key is nested in a list, so you'll have to index the list before you can access the dictionary:

COMMANDS["outcomes"][0]["intent"]
#                    ^ --> dictionary is located at index 0 of the list