こういうJSONスキーマがtest.json
というファイルにストアされていると仮定する。
{
"title": "Person",
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
}
}
}
title
というKeyの要素を取得する場合:
$ python -c "import json; print(json.load(open('test.json','r')).get('title'))"
Person
properties
というKeyの要素を取得する場合:
$ python -c "import json; print(json.load(open('test.json','r')).get('properties'))"
{u'lastName': {u'type': u'string'}, u'firstName': {u'type': u'string'}}
なお、ここでは Python 2.7 における実行結果を記した。