Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

parsing json fields in python

Is there a good tutorial on parsing json attributes in python? I would like to be able to parse the true value for "ok" field. As well as the index named "client_ind_1". I don't understand the python document coverage on this topic. If someone could explain or point me to a better resource, it would be awesome.

My json string looks like the below:

{
    "ok": true,
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "indices": {
        "client_ind_2": {
            "index": {
                "primary_size": "2.5mb",
                "primary_size_in_bytes": 2710326,
                "size": "2.5mb",
                "size_in_bytes": 2710326
            }
        }
    }
}

Thank you in advance.

like image 990
Horse Voice Avatar asked Oct 24 '13 18:10

Horse Voice


1 Answers

import json
dct = json.loads(my_json_str)
is_ok = dct['ok']
client_index = dct['indices']['client_ind_2']['index']
like image 130
shx2 Avatar answered Oct 06 '22 18:10

shx2