I've read that json.loads() can be used by Robot Framework to convert a JSON string to a dictionary in this post: Json handling in ROBOT
So if you define a dictionary-like string like this:
${json_string} Set Variable {"key1": "value1", "key2": "value2", "key3": "value3"}
You can then use the following to convert it to a dictionary:
${dict} Evaluate json.loads('''${json_string}''') json
My question is simple - why are the triple quotes needed here to surround the argument?
If single quotes are used an exception is thrown stating a string must be used:
${dict} Evaluate json.loads('${json_string}') json
(Edit) The above is a bad example, it actually works. If double quotes are used, though, it fails for SyntaxError: invalid syntax.
If no quotes at all are used an error occurs that indicates that the variable is a dictionary - but in Robot it isn't a dictionary (TypeError: the JSON object must be str, bytes or bytearray, not dict):
${dict} Evaluate json.loads(${json_string}) json
If Robot's Convert To String is used on the ${json_string} variable and then that new variable is passed to the json.loads() method the same TypeError occurs stating a string must be used, not a dictionary - but it has been converted to a string:
${json_string2} Convert To String ${json_string}
${dict} Evaluate json.loads(${json_string2}) json
What are the triple quotes accomplishing that are not being accomplished by the other two? This seems to be an aspect of Robot framework...