0

I have this json response, consisting of unicode dictionary and having trouble to convert it as a python dictionary:

u'{
    "event": {
        "event_type": "signature_request_sent",
        "event_time": "1407227830",
        "event_hash": "567b6a342e29ceb8ad3a9641ccd27968f04f2c744c7dd3af8a1922f4eaa5d337",
        "event_metadata": {
            "related_signature_id": null,
            "reported_for_account_id": null,
            "reported_for_app_id": "290e6bb260fed5613b68066084fc77ff",
            "event_message": null
        }
    },
    "account_guid": null,
    "client_id": "290e6bb260fed5613b68066084fc77ff",
    "signature_request": {

        "title": "My First embedded signature request with a template",
        "original_title": "My First embedded signature request with a template",
        "subject": "My First embedded signature request with a template",
        "message": "Awesome, right?",
        "test_mode": true,
        "is_complete": false,
        "has_error": false,
        "custom_fields": [

        ],
        "response_data": [

        ],
        "signing_url": null,
        "signing_redirect_url": null,
        "final_copy_uri": "",
        "signatures": [
            {
                "signature_id": "9c5d829af9e0566134dd28bd064a2fe8",
                "has_pin": false,
                "signer_email_address": "[email protected]",
                "order": null,
                "status_code": "awaiting_signature",
                "signed_at": null,
                "last_viewed_at": null,
                "last_reminded_at": null
            }
        ],
        "cc_email_addresses": [

        ]
    }
}'

tried following solution without success (ValueError for string)

Convert unicode string dictionary into dictionary in python

2
  • 1
    json.loads() will parse it just fine. Commented Aug 5, 2014 at 9:02
  • 1
    Remember to Google your questions. The very first link solves your problem. Commented Aug 5, 2014 at 9:20

2 Answers 2

0
import json
str1 = '{"event": {"event_type": "signature_request_sent","event_time": "1407227830","event_hash": "567b6a342e29ceb8ad3a9641ccd27968f04f2c744c7dd3af8a1922f4eaa5d337","event_metadata": {"related_signature_id": null,"reported_for_account_id": null,"reported_for_app_id": "290e6bb260fed5613b68066084fc77ff","event_message": null}},"account_guid": null,"client_id": "290e6bb260fed5613b68066084fc77ff","signature_request": {"title": "My First embedded signature request with a template","original_title": "My First embedded signature request with a template","subject": "My First embedded signature request with a template","message": "Awesome, right?","test_mode": true,"is_complete": false,"has_error": false,"custom_fields": [],"response_data": [],"signing_url": null,"signing_redirect_url": null,"final_copy_uri": "","signatures": [{"signature_id": "9c5d829af9e0566134dd28bd064a2fe8","has_pin": false,"signer_email_address": "[email protected]","order": null,"status_code": "awaiting_signature","signed_at": null,"last_viewed_at": null,"last_reminded_at": null}],"cc_email_addresses": []}}'
js1 = json.loads(str1)
print type(js1)

This will give you a python dict. use json.loads() to convert your json to python dict. Hope this is helpful to you

Sign up to request clarification or add additional context in comments.

Comments

0

Use json.loads()

>>> a = """{
...     "event": {
...         "event_type": "signature_request_sent",
...         "event_time": "1407227830",
...         "event_hash": "567b6a342e29ceb8ad3a9641ccd27968f04f2c744c7dd3af8a1922f4eaa5d337",
...         "event_metadata": {
...             "related_signature_id": null,
...             "reported_for_account_id": null,
...             "reported_for_app_id": "290e6bb260fed5613b68066084fc77ff",
...             "event_message": null
...         }
        "original_title": "My First embedded signature request with a template",
...     },
...     "account_guid": null,
...     "client_id": "290e6bb260fed5613b68066084fc77ff",
...     "signature_request": {
...
...         "title": "My First embedded signature request with a template",
...         "original_title": "My First embedded signature request with a template",
...         "subject": "My First embedded signature request with a template",
...         "message": "Awesome, right?",
...         "test_mode": true,
...         "is_complete": false,
...         "has_error": false,
...         "custom_fields": [
...
...         ],
...         "response_data": [
...
...         ],
...         "signing_url": null,
...         "signing_redirect_url": null,
...         "final_copy_uri": "",
                "signature_id": "9c5d829af9e0566134dd28bd064a2fe8",
...         "signatures": [
...             {
...                 "signature_id": "9c5d829af9e0566134dd28bd064a2fe8",
...                 "has_pin": false,
...                 "signer_email_address": "[email protected]",
...                 "order": null,
...                 "status_code": "awaiting_signature",
...                 "signed_at": null,
...                 "last_viewed_at": null,
...                 "last_reminded_at": null
...             }
...         ],
...         "cc_email_addresses": [
...
...         ]
...     }
... }"""
>>> import json
>>> import pprint
>>> pprint.pprint(json.loads(a))
{u'account_guid': None,
 u'client_id': u'290e6bb260fed5613b68066084fc77ff',
 u'event': {u'event_hash': u'567b6a342e29ceb8ad3a9641ccd27968f04f2c744c7dd3af8a1922f4eaa5d337',
            u'event_metadata': {u'event_message': None,
                                u'related_signature_id': None,
                                u'reported_for_account_id': None,
                                u'reported_for_app_id': u'290e6bb260fed5613b68066084fc77ff'},
            u'event_time': u'1407227830',
            u'event_type': u'signature_request_sent'},
 u'signature_request': {u'cc_email_addresses': [],
                        u'custom_fields': [],
                        u'final_copy_uri': u'',
                        u'has_error': False,
                        u'is_complete': False,
                        u'message': u'Awesome, right?',
                        u'original_title': u'My First embedded signature request with a template',
                        u'response_data': [],
                        u'signatures': [{u'has_pin': False,
                                         u'last_reminded_at': None,
                                         u'last_viewed_at': None,
                                         u'order': None,
                                         u'signature_id': u'9c5d829af9e0566134dd28bd064a2fe8',
                                         u'signed_at': None,
                                         u'signer_email_address': u'[email protected]',
                                         u'status_code': u'awaiting_signature'}],
                        u'signing_redirect_url': None,
                        u'signing_url': None,
                        u'subject': u'My First embedded signature request with a template',
                        u'test_mode': True,
                        u'title': u'My First embedded signature request with a template'}}
>>>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.