Localstorage get item keyword returns string instead of dict

On browser lib’s LocalStorage Get Item keyword, the value returned ins plain old string.

However, in my usecase, value for a given key is big nested json/dict.

I thought i could just use ${ls}=. Evaluate json.loads(${val}) modules=json or ${ls}=. Evaluate json.loads('${val}') modules=json but neither of these seem to work …

Point being that If i dont explitly convert ${ls} to dict, i cant access sub keys …

Now, ofcourse i can just pass the string to python keyword and json.loads() there and im all set so the question is more about browser lib itself for the usecase of json in the localstorage and evaluate keyword to convert the string into dict as if i dont do that:

String ‘${ls}’ used with invalid index ‘order’. To use ‘[order]’ as a literal value, it needs to be escaped like ‘[order]’.

Hi Rasjani,

my appologies if I misinterpret your request. Do I understand right that you would like to use a more Robo-thonic way to create a dict from a json-string?

As every python module can be a Robot Framework library, you can do the following:

*** Settings ***
Library      json    # this is the ordinary python json module

*** Test Case ***
Demo Use Of JSON module
    ${val}=     Get my json string
    # now call json.loads like a normal keyword
    ${ls}=      Loads     ${val}

${ls} should be a dictionary, now.

Regards,
Markus

2 Likes