Question

After contacting a server I get the following strings as response

{"kind": "t2", "data": {"has_mail": null, "name": "shadyabhi", "created": 1273919273.0, "created_utc": 1273919273.0, "link_karma": 1343, "comment_karma": 301, "is_gold": false, "is_mod": false, "id": "425zf", "has_mod_mail": null}}

which is stored as type 'str' in my script.

Now, when I try to decode it using json.dumps(mystring, sort_keys=True, indent=4), I get this.

"{\"kind\": \"t2\", \"data\": {\"has_mail\": null, \"name\": \"shadyabhi\", \"created\": 1273919273.0, \"created_utc\": 1273919273.0, \"link_karma\": 1343, \"comment_karma\": 301, \"is_gold\": false, \"is_mod\": false, \"id\": \"425zf\", \"has_mod_mail\": null}}"

which should really be like this

shadyabhi@archlinux ~ $ echo '{"kind": "t2", "data": {"has_mail": "null", "name": "shadyabhi", "created": 1273919273.0, "created_utc": 1273919273.0, "link_karma": 1343, "comment_karma": 299, "is_gold": "false", "is_mod": "false", "id": "425zf", "has_mod_mail": "null"}}' | python2 -mjson.tool
{
    "data": {
        "comment_karma": 299, 
        "created": 1273919273.0, 
        "created_utc": 1273919273.0, 
        "has_mail": "null", 
        "has_mod_mail": "null", 
        "id": "425zf", 
        "is_gold": "false", 
        "is_mod": "false", 
        "link_karma": 1343, 
        "name": "shadyabhi"
    }, 
    "kind": "t2"
}
shadyabhi@archlinux ~ $

So, what is it that's going wrong?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top