Reputation: 1291
I have a function that returns a json
formatted dict
. I am using json.dumps()
to store into an object, which I print later on in the code. What I'm getting as a returned isn't the typical json
format I would have expected.
relevant code snippet:
rasa_decoded_output = interpreter.parse(u"{}".format(textobject.body))
rasa_json_formatted_output = json.dumps(rasa_decoded_output)
printing rasa_json_formatted_output
results in this (an example):
("text": "This is a test", "entities": < >, "intent_ranking": < ("confidence": 0.71653000212560282, "name": "st_testing" ), ("confidence": 0.05410130707298815, "name": "exists_item" ), ("confidence": 0.024777391815713805, "name": "concierge_contact_request" ), ("confidence": 0.020174561099034895, "name": "exists_sauna" ), ("confidence": 0.018203983982849743, "name": "issue_bugs" ), ("confidence": 0.017985724341235722, "name": "exists_driver" ), ("confidence": 0.01687271448223236, "name": "request_power_adapter - custom" ), ("confidence": 0.016857156745106013, "name": "request_newroom" ), ("confidence": 0.015943797930370658, "name": "presto_cost" ), ("confidence": 0.015567442054810358, "name": "exists_spa" ) >, "intent": ("confidence": 0.07653000212560282, "name": "st_testing" ) )
What has done wrong here? What should be tweaked to get json to return in its typical format, so that I can parse through and pull out the desired properties.
Also, if I just print rasa_decoded_output
it does the same thing as printing rasa_json_formatted_output
, which suggests json.dumps()
isn't having any effect.
Using json.loads()
on rasa_decoded_output
results in an error TypeError: the JSON object must be str, not 'dict'
Upvotes: 0
Views: 1254
Reputation: 408
The problem might be that rasa_decoded_output
may not be a decoded json object yet. You may need to use json.loads first and once you have done so, you can use json.dumps
Upvotes: 1