I have embedded dictionaries like this:
${json}= Create Dictionary ......(value pairs)
${request}= Create Dictionary body=${json}
${return}= Create Dictionary request=${request}
I can access original key-value pairs like for example this:
${return.request.body.type}
It all works fine. However, I get this error:
Resolving variable '${detail_call.response.json.type}' failed: AttributeError: 'dict' object has no attribute 'type'
When I try to create the initial json object vice-versa - by decoding it from string like this:
${decoded_json}= Run Keyword And Ignore Error json.JSONDecoder.Decode ${response.content}
${response.json}= Set Variable If '${decode_status}' == 'PASS' ${decoded_json} ${null}
${detail_call}= Create Dictionary response=${response}
and accessing it via dot notation:
${detail_call.response.json.type}
When I log the string, I can clearly see there is key "type" with a value assigned. It even works when I access it with brackets:
${detail_call.response.json['type']}
Do you have any idea, why I can't use dot notation if the dictionary was created with JSONDecoder?
Thanks.
dict
s specifically) using dot notation in Python in the first place, unless you're using a different dictionary implementation that allows that. Dot notation is used for attributes of objects, butJSONDecoder
returnsdict
s, so it's perfectly normal to use brackets to access their keys. Also your sample code doesn't seem to be valid Python, is that syntax specific to the Robot framework? - millimoose