I want to read a json file with python like this:
{
"id": "27147e64-9ef5-42d8-b32e-b46b19071ee3b84e0e07-669e-4a10-8124-8e0d71a08e7e",
"image": "img0171.png",
"width": 640,
"height": 480,
"tags": [
{
"name": "becks_long_neck",
"parent": null,
"id": "b2d59c98-0bdc-4d13-ad1b-9d4ab5bc1fb3",
"color": "#e62921",
"type": "bounding_box",
"pos": {
"x": 387,
"y": 310.06667073567706,
"w": 62.666666666666686,
"h": 38.219034830729186
}
},
{
"name": "becks_long_neck",
"parent": null,
"id": "75635f60-e6b9-4408-89fb-ed435355dac6",
"color": "#e62921",
"type": "bounding_box",
"pos": {
"x": 358.5,
"y": 354.06667073567706,
"w": 40.833333333333314,
"h": 31.666666666666686
}
}
]
}
When I want to access to the second name I try something like this:
for dictionary in datastore:
filename = dictionary['image']
tag = dictionary['tags'][0]['name']
if(dictionary['tags'][1]['name']):
tag2 = dictionary['tags'][1]['name']
print(tag)
x = dictionary['tags'][0]['pos']['x']
print(x)
y = dictionary['tags'][0]['pos']['y']
print(y)
w = dictionary['tags'][0]['pos']['w']
print(w)
h = dictionary['tags'][0]['pos']['h']
print(h)
but show me this error:
Traceback (most recent call last):
File "json_to_txt.py", line 65, in <module>
if(dictionary['tags'][1]['name']):
IndexError: list index out of range
How can I access to the second 'name' object?
You don't need to define explicitly each individual variable such as tag, tag2 .. etc . Rather leave this operation to looping, e.g. make it dynamically like in the below case by changing the current order of looping index structure from dictionary[datastore] to datastore[dictionary] :
import json
s = '{"id": "27147e64-9ef5-42d8-b32e-b46b19071ee3b84e0e07-669e-4a10-8124-8e0d71a08e7e","image": "img0171.png","width": 640,"height": 480,"tags": [{"name": "becks_long_neck","parent": null,"id": "b2d59c98-0bdc-4d13-ad1b-9d4ab5bc1fb3","color": "#e62921","type": "bounding_box","pos": {"x": 387,"y": 310.06667073567706,"w": 62.666666666666686,"h": 38.219034830729186}},{"name": "becks_long_neck","parent": null,"id": "75635f60-e6b9-4408-89fb-ed435355dac6","color": "#e62921","type": "bounding_box","pos": {"x": 358.5,"y": 354.06667073567706,"w": 40.833333333333314,"h": 31.666666666666686}}]}'
datastore = json.loads(s)
i=0
for dictionary in datastore:
if dictionary == 'image':
filename = datastore[dictionary]
if dictionary == 'tags':
tag = datastore[dictionary]
for dictionary in tag:
print("tag_name",i,tag[i]['name'])
i+=1
>>>
tag_name 0 becks_long_neck
tag_name 1 becks_long_neck
Related
I am trying to use an online compiler to run my code but it throws the same error of: string indices must be integers. When I run it locally in a jupyter nb, I do not get this error.
What is the program expecting?
`
import json
def solution(content):
content = json.loads(json.dumps(content))
sections = {x["Index"] for x in content['Page_limit']} -IT BREAKS HERE!
Console Output:
Traceback (most recent call last):
File "main.py", line 12, in <module>
res = solution(inp.postcontentstring)
File "/usercode/solution.py", line 6, in solution
sections = {x["Index"] for x in content['Page_Limit']}
TypeError: string indices must be integers
My json looks like this:
postitemsonpage = {
"Page_Limit": [
{
"id": "0",
"index": 0
},
{
"id": "1",
"index": 2
},
{
"id": "2",
"index": 4
}
]}
I think your postitemsonpage type is string, so you got the TypeError: string indices must be integers Error.
code:
import json
def solution(content):
content = json.loads(content)
sections = {x["index"] for x in content['Page_Limit']} #-if you use json.loads(json.dumps(content)) you got a TypeError: string indices must be integers HERE!
return sections
postitemsonpage = """{
"Page_Limit": [
{
"id": "0",
"index": 0
},
{
"id": "1",
"index": 2
},
{
"id": "2",
"index": 4
}
]}
"""
print(solution(postitemsonpage))
result:
{0, 2, 4}
This works:
import json
def solver(content):
content = json.loads(json.dumps(content))
sections = {x["index"] for x in content['Page_Limit']}
postitemsonpage = {
"Page_Limit": [
{
"id": "0",
"index": 0
},
{
"id": "1",
"index": 2
},
{
"id": "2",
"index": 4
}
]}
solver(postitemsonpage)
You had spelling errors:
sections = {x["index"] for x in content['Page_Limit']}
and not
sections = {x["Index"] for x in content['Page_limit']}
index is a key which points to an integer whereas Index is a string. Hence the error TypeError: string indices must be integers.
import json
postitemsonpage = {
"Page_Limit": [
{
"id": "0",
"index": 0
},
{
"id": "1",
"index": 2
},
{
"id": "2",
"index": 4
}
]}
def solution(content):
content = json.loads(json.dumps(content))
sections = {x["index"] for x in content['Page_Limit']}
solution(postitemsonpage)
This code seems to work. Perhaps your particular error was in loading this:
postitemsonpage = {
"Page_Limit": [
{
"id": "0",
"index": 0
},
{
"id": "1",
"index": 2
},
{
"id": "2",
"index": 4
} ]}
as a string entirely. I don't know, but this works.
I want to delete json objects if value found in the json body. Please see below code and json body. I tried in python but getting error : [TypeError: list indices must be integers or slices, not str]
import json
import sys
key = ['1']
myData = [
{
"id": 1,
"modifiedBy": "admin",
"fields": {
"Application": "1",
"Endtermin": 23011990
}
},
{
"id": 2,
"modifiedBy": "admin",
"fields": {
"Application": "2",
"Endtermin": 11021990
}
}
]
# delete json objects.
[x for x in myData['fields'] if x["Application"] != 'key']
For example : In the json body, I will look for the Application value, when matching with key, then I want to delete json objects. Here i want to delete first json objects because key value is matching with Application value.
My results looks like here.
myData = [
{
"id": 2,
"modifiedBy": "admin",
"fields": {
"Application": "2",
"Endtermin": 11021990
}
}
]
You mixed several things up here.
myData is a list, therefore you cannot access any item in it via a string (that's what the error tells you)
You should not check for 'key', but for key[0]
key does not need to be a list
So here's how to fix this:
import json
import sys
key = "1" # point 3 from above
myData = [
{
"id": 1,
"modifiedBy": "admin",
"fields": {
"Application": "1",
"Endtermin": 23011990
}
},
{
"id": 2,
"modifiedBy": "admin",
"fields": {
"Application": "2",
"Endtermin": 11021990
}
}
]
# delete json objects. This overwrites myData
myData = [x for x in myData if x["fields"]["Application"] != key] # points 1 and 2
If you really need key to be a list because it may contain several keys, I'd suggest following changes:
keys = ["1", "5"]
# myData is still the same
# ...
myData = [x for x in myData if x["fields"]["Application"] not in keys]
This should yield your desired filtering
[x for x in myData if x['fields']['Application'] not in key]
iterates over the list of entries in myData and check for each entry x whether it's property x['fields']['Application'] is not in the list of key which you want to filter
Full code:
import json
import sys
key = ['1']
myData = [
{
"id": 1,
"modifiedBy": "admin",
"fields": {
"Application": "1",
"Endtermin": 23011990
}
},
{
"id": 2,
"modifiedBy": "admin",
"fields": {
"Application": "2",
"Endtermin": 11021990
}
}
]
# delete json objects.
myData2 = [x for x in myData if x['fields']['Application'] not in key]
print(myData2)
I have a json file that looks something like this (I've left a lot out to keep it shorter so ignore missing brackets in it):
{
"id": "79cb20b0-02be-42c7-9b45-96407c888dc2",
"tenantId": "00000000-0000-0000-0000-000000000000",
"name": "2-stufiges Stirnradgetriebe",
"description": null,
"visibility": "None",
"method": "IDM_CALCULATE_GEAR_COUPLED",
"created": "2018-10-16T10:25:20.874Z",
"createdBy": "00000000-0000-0000-0000-000000000000",
"lastModified": "2018-10-16T10:25:28.226Z",
"lastModifiedBy": "00000000-0000-0000-0000-000000000000",
"client": "STRING_BEARINX_ONLINE",
"project": {
"id": "10c37dcc-0e4e-4c4d-a6d6-12cf65cceaf9",
"name": "proj 2",
"isBookmarked": false
},
"rootObject": {
"id": "6ff0010c-00fe-485b-b695-4ddd6aca4dcd",
"type": "IDO_GEAR",
"children": [
{
"id": "1dd94d1a-e52d-40b3-a82b-6db02a8fbbab",
"type": "IDO_SYSTEM_LOADCASE",
"children": [],
"childList": "SYSTEMLOADCASE",
"properties": [
{
"name": "IDCO_IDENTIFICATION",
"value": "1dd94d1a-e52d-40b3-a82b-6db02a8fbbab"
},
{
"name": "IDCO_DESIGNATION",
"value": "Lastfall 1"
},
{
"name": "IDSLC_TIME_PORTION",
"value": 100
},
{
"name": "IDSLC_DISTANCE_PORTION",
"value": 100
},
{
"name": "IDSLC_OPERATING_TIME_IN_HOURS",
"value": 1
},
{
"name": "IDSLC_OPERATING_TIME_IN_SECONDS",
"value": 3600
},
{
"name": "IDSLC_OPERATING_REVOLUTIONS",
"value": 1
},
{
"name": "IDSLC_OPERATING_DISTANCE",
"value": 1
},
{
"name": "IDSLC_ACCELERATION",
"value": 9.81
},
{
"name": "IDSLC_EPSILON_X",
"value": 0
},
{
"name": "IDSLC_EPSILON_Y",
"value": 0
},
{
"name": "IDSLC_EPSILON_Z",
"value": 0
},
{
"name": "IDSLC_CALCULATION_WITH_OWN_WEIGHT",
"value": "CO_CALCULATION_WITHOUT_OWN_WEIGHT"
},
{
"name": "IDSLC_CALCULATION_WITH_TEMPERATURE",
"value": "CO_CALCULATION_WITH_TEMPERATURE"
},
{
"name": "IDSLC_FLAG_FOR_LOADCASE_CALCULATION",
"value": "LB_CALCULATE_LOADCASE"
},
{
"name": "IDSLC_STATUS_OF_LOADCASE_CALCULATION",
"value": false
}
],
"position": 1,
"order": 1,
"support_vector": {
"x": 0,
"y": 0,
"z": 0
},
"u_axis_vector": {
"x": 1,
"y": 0,
"z": 0
},
"w_axis_vector": {
"x": 0,
"y": 0,
"z": 1
},
"role": "_none_"
},
{
"id": "ab7fbf37-17bb-4e60-a543-634571a0fd73",
"type": "IDO_SHAFT_SYSTEM",
"children": [
{
"id": "7f034e5c-24df-4145-bab8-601f49b43b50",
"type": "IDO_RADIAL_ROLLER_BEARING",
"children": [
{
"id": "0b3e695b-6028-43af-874d-4826ab60dd3f",
"type": "IDO_RADIAL_BEARING_INNER_RING",
"children": [
{
"id": "330aa09d-60fb-40d7-a190-64264b3d44b7",
"type": "IDO_LOADCONTAINER",
"children": [
{
"id": "03036040-fc1a-4e52-8a69-d658e18a8d4a",
"type": "IDO_DISPLACEMENT",
"children": [],
"childList": "DISPLACEMENT",
"properties": [
{
"name": "IDCO_IDENTIFICATION",
"value": "03036040-fc1a-4e52-8a69-d658e18a8d4a"
},
{
"name": "IDCO_DESIGNATION",
"value": "Displacement 1"
}
]
I want to add entries to it but the problem is the location I want to add it isn't uniform. The id key will change, for example sometimes I may want to add the entries to "id": "ab7fbf37-17bb-4e60-a543-634571a0fd73" and another I might want to add the entries to "id": "0b3e695b-6028-43af-874d-4826ab60dd3f".
The code I have runs through another file in a loop and every time it finds a id and a property name it stores the id, name, and value.
The code I'm currently using is:
import os
import json
import shutil
import re
import fileinput
#Finds and lists the folders that have been provided
d='.'
folders = list(filter (lambda x: os.path.isdir(os.path.join(d, x)), os.listdir(d)))
print("Folders found: ")
print(folders)
print("\n")
def processModelFolder(inFolder):
#Creating the file names
fileName = os.path.join(d, inFolder, inFolder + ".mdl")
fileNameTwo = os.path.join(d, inFolder, inFolder + ".vg2.json")
fileNameThree = os.path.join(d, inFolder, inFolder + "APPENDED.vg2.json")
#copying the json file so the new copy can be appended
shutil.copyfile(fileNameTwo, fileNameThree)
#assigning IDs and properties to search for in the mdl file
IDs = ["7f034e5c-24df-4145-bab8-601f49b43b50"]
Properties = ["IDSU_FX[0]","IDSU_FY[0]","IDSU_FZ[0]"]
#Basic check to see if IDs and Properties are valid
for i in IDs:
if len(i) != 36:
print("ID may not have been valid and might not return the results you expect, check to ensure the characters are correct: ")
print(i)
print("\n")
if len(IDs) == 0:
print("No IDs were given!")
elif len(Properties) == 0:
print("No Properties were given!")
#Reads code untill an ID is found
else:
with open(fileName , "r") as in_file:
IDCO = None
for n, line in enumerate(in_file, 1):
if line.startswith('IDCO_IDENTIFICATION'):
#Checks if the second part of each line is a ID tag in IDs
if line.split('"')[1] in IDs:
#If ID found it is stored as IDCO
IDCO = line.split('"')[1]
else:
if IDCO:
pass
IDCO = None
#Checks if the first part of each line is a Prop in Propterties
elif IDCO and line.split(' ')[0] in Properties:
print('Found! ID:{} Prop:{} Value: {}'.format(IDCO, line.split('=')[0][:-1], line.split('=')[1][:-1]))
print("\n")
#Stores the property name and value
name = str(line.split(' ')[0])
value = str(line.split(' ')[2])
print(name)
print(value)
#json file editing
with open(fileNameThree , "r+") as json_data:
python_obj = json.load(json_data)
new_element = [{"name": name, "value":value}]
python_obj['"id": "485f5bf4-fb97-415b-8b42-b46e9be080da"']
#foreach in new_elements:
#data['rootObject']['children'][0]['properties'].append(each)
print('Processed {} lines in file {}'.format(n , fileName))
for modelFolder in folders:
processModelFolder(modelFolder)
Is there any obvious way to dynamically change where it places the new entries? I'm having a hard time because the indent level it may be changes.
**Updated code:
import os
import json
import shutil
import re
import fileinput
#Finds and lists the folders that have been provided
d='.'
folders = list(filter (lambda x: os.path.isdir(os.path.join(d, x)), os.listdir(d)))
print("Folders found: ")
print(folders)
print("\n")
def processModelFolder(inFolder):
#Creating the file names
fileName = os.path.join(d, inFolder, inFolder + ".mdl")
fileNameTwo = os.path.join(d, inFolder, inFolder + ".vg2.json")
fileNameThree = os.path.join(d, inFolder, inFolder + "APPENDED.vg2.json")
#copying the json file so the new copy can be appended
shutil.copyfile(fileNameTwo, fileNameThree)
#assigning IDs and properties to search for in the mdl file
IDs = ["7f034e5c-24df-4145-bab8-601f49b43b50"]
Properties = ["IDSU_FX[0]","IDSU_FY[0]","IDSU_FZ[0]"]
#Basic check to see if IDs and Properties are valid
for i in IDs:
if len(i) != 36:
print("ID may not have been valid and might not return the results you expect, check to ensure the characters are correct: ")
print(i)
print("\n")
if len(IDs) == 0:
print("No IDs were given!")
elif len(Properties) == 0:
print("No Properties were given!")
#Reads code untill an ID is found
else:
with open(fileName , "r") as in_file:
IDCO = None
for n, line in enumerate(in_file, 1):
if line.startswith('IDCO_IDENTIFICATION'):
#Checks if the second part of each line is a ID tag in IDs
if line.split('"')[1] in IDs:
#If ID found it is stored as IDCO
IDCO = line.split('"')[1]
else:
if IDCO:
pass
IDCO = None
#Checks if the first part of each line is a Prop in Propterties
elif IDCO and line.split(' ')[0] in Properties:
print('Found! ID:{} Prop:{} Value: {}'.format(IDCO, line.split('=')[0][:-1], line.split('=')[1][:-1]))
print("\n")
#Stores the property name and value
name = str(line.split(' ')[0])
value = str(line.split(' ')[2])
key = os.path.join('"id": "'+IDCO+'"')
print(key)
print(name)
print(value)
#json file editing
with open(fileNameThree , "r+") as json_data:
python_obj = json.load(json_data)
new_element = [{"name": name, "value":value}]
print("NEW ELEMENT:")
print(new_element)
for each in new_element:
children = {x['id']: x for x in python_obj['rootObject']['children']}
children[IDs]['properties'].append(each)
python_obj['rootObject']['children'] = [x for _, x in children.items()]
with open(fileNameThree , "w") as json_data:
json.dump(python_obj, json_data, indent = 3)
print('Processed {} lines in file {}'.format(n , fileName))
for modelFolder in folders:
processModelFolder(modelFolder)
You can convert the 'children' list into an dict.
children = {x['id']: x for x in data['rootObject']['children']}
Or if order matters to you do:
od = OrderedDict()
for child in children:
od[child['id']] = child
Then do the insertion based on id as
children[<<id here>>]['properties'].append(each)
Then convert dict back to list
data['rootObject']['children'] = [x for _, x in children.items()]
I'm working with multiple JSON objects where they are converted to nested dictionaries in which the last dictionary is extracted (as shown in "Data" segment). I want to extract all values of "Tags" into a list. WHile I'm trying to do this, I'm getting the output followed by an error.
Code:
import json
with open('console_data.json', 'r') as console_data:
parsed_data = console_data.read()
nodes = json.loads(parsed_data)
last_node = nodes[-1] # extract last dictionary
print("\n\n\n")
for item in last_node:
tags = last_node[item].get("Tags", {})
try:
print(tags)
except AttributeError:
pass
Data:
{
"Node": {
"ID": "1a2b78dc-078d-cfe2-6c55-189aa2c67d29",
"Node": "NAVIAPP05",
"Address": "10.2.2.5",
"Datacenter": "naviprod",
"TaggedAddresses": {
"lan": "10.2.2.5",
"wan": "10.2.2.5"
},
"Meta": {
"consul-network-segment": ""
},
"CreateIndex": 5171424,
"ModifyIndex": 5453151
},
"Service": {
"ID": "sim-work102235-10185",
"Service": "sim",
"Tags": [
"fc216ed1-ef55-4064-b25d-de37ac612984",
"2a82837f-1867-4b59-ab21-72331b75f4c2",
"732b3fc1-687b-42ac-b71f-d755fe90de04",
"d85d8902-8c36-4591-8f39-b4d8528301ce",
"d5d695a6-710f-4edc-ae03-47ee034137a4",
"62002f4a-4029-4f4f-a9d0-6b0fc2f34951",
"459cc8e3-fc44-43ce-9d7f-dfa3fe92665e"
],
"Address": "10.2.2.35",
"Meta": {
"apiContext": "/sim/sim.do",
"defaultContext": "/sim",
"workflowContext": "/sim/services",
"zspContext": "/sim/services",
"zspProductURL": "https://sim.abcde.com/sim/"
},
"Port": 10185,
"EnableTagOverride": false,
"CreateIndex": 7327367,
"ModifyIndex": 7327367
},
"Checks": [
{
"Node": "NAVIAPP05",
"CheckID": "serfHealth",
"Name": "Serf Health Status",
"Status": "passing",
"Notes": "",
"Output": "Agent alive and reachable",
"ServiceID": "",
"ServiceName": "",
"ServiceTags": [],
"Definition": {},
"CreateIndex": 5171424,
"ModifyIndex": 5171424
}
]
}
Output:
{}
['fc216ed1-ef55-4064-b25d-de37ac612984', '2a82837f-1867-4b59-ab21-72331b75f4c2', '732b3fc1-687b-42ac-b71f-d755fe90de04', 'd85d8902-8c36-4591-8f39-b4d8528301ce', 'd5d695a6-710f-4edc-ae03-47ee034137a4', '62002f4a-4029-4f4f-a9d0-6b0fc2f34951', '459cc8e3-fc44-43ce-9d7f-dfa3fe92665e']
Traceback (most recent call last):
File "so_parse_json.py", line 12, in <module>
tags = last_dict[item].get("Tags", {})
AttributeError: 'list' object has no attribute 'get'
Expected Output:
['fc216ed1-ef55-4064-b25d-de37ac612984', '2a82837f-1867-4b59-ab21-72331b75f4c2', '732b3fc1-687b-42ac-b71f-d755fe90de04', 'd85d8902-8c36-4591-8f39-b4d8528301ce', 'd5d695a6-710f-4edc-ae03-47ee034137a4', '62002f4a-4029-4f4f-a9d0-6b0fc2f34951', '459cc8e3-fc44-43ce-9d7f-dfa3fe92665e']
Assuming that Data you enclosed is from last_node, why not just use:
last_node['Service']['Tags']
This outputs:
['fc216ed1-ef55-4064-b25d-de37ac612984',
'2a82837f-1867-4b59-ab21-72331b75f4c2',
'732b3fc1-687b-42ac-b71f-d755fe90de04',
'd85d8902-8c36-4591-8f39-b4d8528301ce',
'd5d695a6-710f-4edc-ae03-47ee034137a4',
'62002f4a-4029-4f4f-a9d0-6b0fc2f34951',
'459cc8e3-fc44-43ce-9d7f-dfa3fe92665e']
I don't know what's in your console_data.json. This code works on Data above.
import json
with open('Data.json','r') as f:
data = f.read()
nodes = json.loads(data)
tags = nodes['Service']['Tags']
print(tags)
I have been working on this code for a few hours trying a bunch of things to iterate through the supplied json data. Can figure out how to properly iterate through these nested lists and objects.
import json
data = """
{
"tracks": "1",
"timeline": {
"0.733251541": [
{
"id": 1,
"bounds": {
"Width": 0.5099463905313426,
"Height": 0.2867199993133546,
"Y": 0.4436400003433228,
"X": 0.4876505160745349
}
}
],
"0.965": [
{
"id": 1,
"bounds": {
"Width": 0.4205311330135182,
"Height": 0.2363199994340539,
"Y": 0.2393400002829731,
"X": 0.1593787633901481
}
}
],
"1.098224": [
{
"id": 1,
"bounds": {
"Width": 0.4568560813801344,
"Height": 0.2564799993857742,
"Y": 0.1992600003071129,
"X": 0.1000513407532317
}
}
]
},
"taggedTracks": {
"1": "dirk"
}
}
"""
json = json.loads(data)
for a in json["timeline"]:
for b in a:
for c in b["bounds"]:
print a, c["Width"], c["Height"], c["Y"], c["X"]
Can someone please steer me in the right direction on how to deal with the json data supplied?
I get the following error.
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
TypeError: string indices must be integers
You are getting the the TypeError because inside each value of "timeline", first comes a list. You have to take the first value of that list, using the index of 0. Then you can parse the rest.
Hopefully the following code helps:
import json
data = """
{
"tracks": "1",
"timeline": {
"0.733251541": [
{
"id": 1,
"bounds": {
"Width": 0.5099463905313426,
"Height": 0.2867199993133546,
"Y": 0.4436400003433228,
"X": 0.4876505160745349
}
}
],
"0.965": [
{
"id": 1,
"bounds": {
"Width": 0.4205311330135182,
"Height": 0.2363199994340539,
"Y": 0.2393400002829731,
"X": 0.1593787633901481
}
}
],
"1.098224": [
{
"id": 1,
"bounds": {
"Width": 0.4568560813801344,
"Height": 0.2564799993857742,
"Y": 0.1992600003071129,
"X": 0.1000513407532317
}
}
]
},
"taggedTracks": {
"1": "dirk"
}
}
"""
test_json = json.loads(data)
for num, data in test_json["timeline"].iteritems():
print(num+":")
bounds = data[0]["bounds"]
for bound, value in bounds.iteritems():
print('\t'+bound+": "+str(value))
First of all, it's not a great idea to use the name json for a variable since that is the name of the module. Let's use j instead.
Anyway, when you do json.loads(), you get back a dict. When you iterate for a in <dict>, you get back the list of keys (only). You can instead iterate over the keys and values with iteritems(), like:
for k, a in j['timeline'].iteritems():
for b in a:
c = b['bounds']
print k, c["Width"], c["Height"], c["Y"], c["X"]