I dont know how to iterate these json file using forloop i tried this it printing all content but i need to print only the id and class.
for (k, v) in bin3.items():
if k == 'ID':
print(v)
The above code doesnt print anything.
this is my json file content
{
"content": {
"ID": "stringIdentity:@5",
"class": 1,
"annotations": [
{
"ID": 1,
"class": 2,
"body": ""
}]}}
dir_with_bin_folder=[]
for root, directories, files in os.walk(directory):
for filename in files:
if filename=='@3.bin':
with open(root+'/'+filename) as json_file:
bin3 = json.load(json_file)
df = pd.read_json(root+'/'+filename)
print(filename)
print(bin3)
annotations=bin3['annotations']
bin3_content=(bin3['content'])
bin3_IID=(bin3['ID')
bin3_class=(bin3['class'])
for i in annotations:
bin3_ID=(i['ID'])
bin3_class=(i['class'])
bin3_body=(i['body'])
print(bin3_ID)
And i tried this above one also but im getting keyvalue error