python - parse json without explciitely calling the key-name -
i have json-like file valid json per line looks
{"some_key": {"name": "tom", "school_code":"5678", "sport": "football", "score":"3.46", "classid": "456"}} {"another_one": {"name": "helen", "school_code":"7657", "sport": ["swimming", "score":"9.8", "classid": "865"}} {"yet_another_one_": {"name": "mikle", "school_code":"7655", "sport": "tennis", "score":"5.7", "classid": "76532"}}
so need create dictionary(? not need dictionary format me associate key value, array of 2 elements ex) extracting these first keys (i.e. "some_key", "another_key" etc), don't know in advance, , associating them value of score key inside dictionary. like:
("some_key":"3.46", "another_key":"9.8", "yet_another_one_"; "5.7")
i don't know method extract content without calling key-name explicitly, ideas more welcome !
this works python2 , python3
>>> {k: v.get('score') item in data k, v in item.items()} {'another_one': '9.8', 'some_key': '3.46', 'yet_another_one_': '5.7'}
Comments
Post a Comment