I Am trying to load a json data file into a variable directly in Robot Framework. Can anyone please elaborate with an e.g. giving the exact syntax as to how to do it? Thanks in advance :)
One way would be to use the Get File keyword from the OperatingSystem library, and then use the built-in Evaluate keyword to convert it to a python object.
For example, consider a file named example.json with the following contents:
{
"firstname": "Inigo",
"lastname": "Montoya"
}
You can log the name with something like this:
*** Settings ***
| Library | OperatingSystem
*** Test Cases ***
| Example of how to load JSON
| | # read the raw data
| | ${json}= | Get file | example.json
| |
| | # convert the data to a python object
| | ${object}= | Evaluate | json.loads('''${json}''') | json
| |
| | # log the data
| | log | Hello, my name is ${object["firstname"]} ${object["lastname"]} | WARN
Of course, you could also write your own library in python to create a keyword that does the same thing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With