から特定のフィールドを抽出するために、私は次のようなJSON文字列を持っていると私はdoc_count
を取得したい:どのようにJSON文字列
import json
text = '''{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 11,
"max_score": 0,
"hits": []
},
"aggregations": {
"range": {
"buckets": [
{
"key": "2017-02-17T15:00:00.000Z-2017-02-17T16:00:00.000Z",
"from": 1487343600000,
"from_as_string": "2017-02-17T15:00:00.000Z",
"to": 1487347200000,
"to_as_string": "2017-02-17T16:00:00.000Z",
"doc_count": 2
}
]
}
}
}'''
obj = json.loads(text)
obj
私はobj['aggregations']['range']['buckets']['doc_count']
を試してみましたが、それは動作しません。このJSONファイルの階層を検索するにはどうすればよいですか?